ai_pdf/backend/logger.py
Crizomb 18f35b28c2 * added log tab
* added references text box
* added options to choose embedding models
2024-04-20 12:54:24 +02:00

33 lines
710 B
Python

import gradio as gr
import sys
class Logger:
"""
Logger class to redirect the output to a file.
will be used to the log textbox in the frontend.
Adapted from : https://github.com/gradio-app/gradio/issues/2362#issuecomment-1424446778
"""
def __init__(self, filename):
self.terminal = sys.stdout
self.log = open(filename, "w")
def write(self, message):
self.terminal.write(message)
self.log.write(message)
def flush(self):
self.terminal.flush()
self.log.flush()
def isatty(self):
return False
def read_logs():
sys.stdout.flush()
with open("../temp_file/output.log", "r") as f:
return f.read()