Spaces:
Runtime error
Runtime error
Commit
·
59891c7
1
Parent(s):
d421a6e
correct logger
Browse files
app.py
CHANGED
|
@@ -519,6 +519,24 @@ def func_upload_file(files, chat_history):
|
|
| 519 |
chat_history.append(test_msg)
|
| 520 |
yield chat_history
|
| 521 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 522 |
def read_logs():
|
| 523 |
sys.stdout.flush()
|
| 524 |
with open("output.log", "r") as f:
|
|
@@ -526,14 +544,13 @@ def read_logs():
|
|
| 526 |
|
| 527 |
with gr.Blocks() as demo:
|
| 528 |
# gr.Markdown("Start typing below and then click **SUBMIT** to see the output.")
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
)
|
| 535 |
-
logs = gr.Textbox()
|
| 536 |
upload_button = gr.UploadButton("Upload File", file_count="multiple")
|
|
|
|
| 537 |
upload_button.upload(func_upload_file, [upload_button, main.chatbot], main.chatbot)
|
| 538 |
demo.load(read_logs, None, logs, every=2)
|
| 539 |
|
|
|
|
| 519 |
chat_history.append(test_msg)
|
| 520 |
yield chat_history
|
| 521 |
|
| 522 |
+
class Logger:
|
| 523 |
+
def __init__(self, filename):
|
| 524 |
+
self.terminal = sys.stdout
|
| 525 |
+
self.log = open(filename, "w")
|
| 526 |
+
|
| 527 |
+
def write(self, message):
|
| 528 |
+
self.terminal.write(message)
|
| 529 |
+
self.log.write(message)
|
| 530 |
+
|
| 531 |
+
def flush(self):
|
| 532 |
+
self.terminal.flush()
|
| 533 |
+
self.log.flush()
|
| 534 |
+
|
| 535 |
+
def isatty(self):
|
| 536 |
+
return False
|
| 537 |
+
|
| 538 |
+
sys.stdout = Logger("output.log")
|
| 539 |
+
|
| 540 |
def read_logs():
|
| 541 |
sys.stdout.flush()
|
| 542 |
with open("output.log", "r") as f:
|
|
|
|
| 544 |
|
| 545 |
with gr.Blocks() as demo:
|
| 546 |
# gr.Markdown("Start typing below and then click **SUBMIT** to see the output.")
|
| 547 |
+
main = gr.ChatInterface(
|
| 548 |
+
chathmi2,
|
| 549 |
+
title="STLA BABY - YOUR FRIENDLY GUIDE",
|
| 550 |
+
description= "v0.3: Powered by MECH Core Team",
|
| 551 |
+
)
|
|
|
|
|
|
|
| 552 |
upload_button = gr.UploadButton("Upload File", file_count="multiple")
|
| 553 |
+
logs = gr.Textbox()
|
| 554 |
upload_button.upload(func_upload_file, [upload_button, main.chatbot], main.chatbot)
|
| 555 |
demo.load(read_logs, None, logs, every=2)
|
| 556 |
|