Spaces:
Runtime error
Runtime error
Michael S. Trusov commited on
Commit ·
654d791
1
Parent(s): 1158c06
November 3 commit to Hugging Face
Browse files
app.py
CHANGED
|
@@ -11,16 +11,6 @@ import time
|
|
| 11 |
import numpy as np
|
| 12 |
import json
|
| 13 |
|
| 14 |
-
#--------------------------------------------------------------------------------
|
| 15 |
-
|
| 16 |
-
from fastapi import FastAPI
|
| 17 |
-
from fastapi.responses import PlainTextResponse
|
| 18 |
-
|
| 19 |
-
#--------------------------------------------------------------------------------
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
qs = {}
|
| 25 |
|
| 26 |
theme = gr.themes.Base(
|
|
@@ -32,34 +22,6 @@ theme = gr.themes.Base(
|
|
| 32 |
)
|
| 33 |
|
| 34 |
|
| 35 |
-
# --------------------------------------------------------------------------------------------
|
| 36 |
-
|
| 37 |
-
def print_log_file():
|
| 38 |
-
"""Prints the contents of the log file 'images/log_data.txt'."""
|
| 39 |
-
try:
|
| 40 |
-
with open('images/log_data.txt', 'r') as log_file:
|
| 41 |
-
log_content = log_file.read()
|
| 42 |
-
return log_content
|
| 43 |
-
except FileNotFoundError:
|
| 44 |
-
return "Log file not found."
|
| 45 |
-
|
| 46 |
-
# --------------------------------------------------------------------------------------------
|
| 47 |
-
|
| 48 |
-
# --------------------------------------------------------------------------------------------
|
| 49 |
-
|
| 50 |
-
def delete_log_file():
|
| 51 |
-
"""Deletes the log file 'images/log_data.txt' if it exists."""
|
| 52 |
-
try:
|
| 53 |
-
if os.path.exists('images/log_data.txt'):
|
| 54 |
-
os.remove('images/log_data.txt')
|
| 55 |
-
return "Log file deleted successfully."
|
| 56 |
-
else:
|
| 57 |
-
return "Log file does not exist."
|
| 58 |
-
except Exception as e:
|
| 59 |
-
return f"Error deleting log file: {e}"
|
| 60 |
-
|
| 61 |
-
# --------------------------------------------------------------------------------------------
|
| 62 |
-
|
| 63 |
import uuid
|
| 64 |
|
| 65 |
# Add a function to generate a unique session ID
|
|
@@ -112,6 +74,35 @@ with gr.Blocks(theme = theme) as demo:
|
|
| 112 |
chatbot = gr.Chatbot(elem_id="chatbot", layout = "panel", avatar_images=("images/user.jpg", "images/bot.jpg"),latex_delimiters=[],)
|
| 113 |
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
# height=800,
|
| 117 |
|
|
@@ -399,25 +390,6 @@ def log_message(param, session_id):
|
|
| 399 |
print(f'Writing to Log file: {abs_path}')
|
| 400 |
|
| 401 |
|
| 402 |
-
|
| 403 |
-
#--------------------------------------------------------------------------------
|
| 404 |
-
|
| 405 |
-
app = FastAPI()
|
| 406 |
-
|
| 407 |
-
@app.get("/get_log", response_class=PlainTextResponse)
|
| 408 |
-
async def get_log_file():
|
| 409 |
-
try:
|
| 410 |
-
with open("images/log_data.txt", "r") as file:
|
| 411 |
-
return file.read()
|
| 412 |
-
except FileNotFoundError:
|
| 413 |
-
return "Log file not found."
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
# Mount Gradio app to FastAPI
|
| 417 |
-
#app = gr.mount_gradio_app(app, demo, path="/")
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
# --------------------------------------------------------------------------------------------
|
| 422 |
# Launching
|
| 423 |
# --------------------------------------------------------------------------------------------
|
|
|
|
| 11 |
import numpy as np
|
| 12 |
import json
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
qs = {}
|
| 15 |
|
| 16 |
theme = gr.themes.Base(
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
import uuid
|
| 26 |
|
| 27 |
# Add a function to generate a unique session ID
|
|
|
|
| 74 |
chatbot = gr.Chatbot(elem_id="chatbot", layout = "panel", avatar_images=("images/user.jpg", "images/bot.jpg"),latex_delimiters=[],)
|
| 75 |
|
| 76 |
|
| 77 |
+
# --------------------------------------------------------------------------------------------
|
| 78 |
+
|
| 79 |
+
def print_log_file():
|
| 80 |
+
"""Prints the contents of the log file 'images/log_data.txt'."""
|
| 81 |
+
try:
|
| 82 |
+
with open('images/log_data.txt', 'r') as log_file:
|
| 83 |
+
log_content = log_file.read()
|
| 84 |
+
return log_content
|
| 85 |
+
except FileNotFoundError:
|
| 86 |
+
return "Log file not found."
|
| 87 |
+
|
| 88 |
+
# --------------------------------------------------------------------------------------------
|
| 89 |
+
|
| 90 |
+
# --------------------------------------------------------------------------------------------
|
| 91 |
+
|
| 92 |
+
def delete_log_file():
|
| 93 |
+
"""Deletes the log file 'images/log_data.txt' if it exists."""
|
| 94 |
+
try:
|
| 95 |
+
if os.path.exists('images/log_data.txt'):
|
| 96 |
+
os.remove('images/log_data.txt')
|
| 97 |
+
return "Log file deleted successfully."
|
| 98 |
+
else:
|
| 99 |
+
return "Log file does not exist."
|
| 100 |
+
except Exception as e:
|
| 101 |
+
return f"Error deleting log file: {e}"
|
| 102 |
+
|
| 103 |
+
# --------------------------------------------------------------------------------------------
|
| 104 |
+
|
| 105 |
+
|
| 106 |
|
| 107 |
# height=800,
|
| 108 |
|
|
|
|
| 390 |
print(f'Writing to Log file: {abs_path}')
|
| 391 |
|
| 392 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
# --------------------------------------------------------------------------------------------
|
| 394 |
# Launching
|
| 395 |
# --------------------------------------------------------------------------------------------
|