Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import torch
|
|
2 |
from transformers import pipeline
|
3 |
import gradio as gr
|
4 |
import threading
|
|
|
5 |
|
6 |
# Global variable to store the model pipeline
|
7 |
model_pipeline = None
|
@@ -76,6 +77,13 @@ def reload_model_button():
|
|
76 |
load_model()
|
77 |
return "Model reloaded successfully."
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
# Gradio Interface
|
80 |
with gr.Blocks() as demo:
|
81 |
gr.Markdown("# DeepSeek-R1 Chatbot")
|
@@ -92,13 +100,6 @@ with gr.Blocks() as demo:
|
|
92 |
|
93 |
status_text = gr.Textbox(label="Model Status", value="Model not loaded yet.", interactive=False)
|
94 |
|
95 |
-
def update_status():
|
96 |
-
"""Update the model status text."""
|
97 |
-
if model_loaded:
|
98 |
-
return "Model is loaded and ready."
|
99 |
-
else:
|
100 |
-
return "Model is not loaded."
|
101 |
-
|
102 |
def respond(message, chat_history):
|
103 |
bot_message = chat(message, chat_history)
|
104 |
chat_history.append((message, bot_message))
|
@@ -108,10 +109,10 @@ with gr.Blocks() as demo:
|
|
108 |
clear_button.click(lambda: [], None, chatbot)
|
109 |
reload_button.click(reload_model_button, None, status_text)
|
110 |
|
111 |
-
#
|
112 |
-
|
113 |
|
114 |
# Load the model when the server starts
|
115 |
if __name__ == "__main__":
|
116 |
load_model() # Pre-load the model
|
117 |
-
demo.launch(server_name="0.0.0.0")
|
|
|
2 |
from transformers import pipeline
|
3 |
import gradio as gr
|
4 |
import threading
|
5 |
+
import time
|
6 |
|
7 |
# Global variable to store the model pipeline
|
8 |
model_pipeline = None
|
|
|
77 |
load_model()
|
78 |
return "Model reloaded successfully."
|
79 |
|
80 |
+
# Function to periodically update the status text
|
81 |
+
def update_status_periodically(status_text):
|
82 |
+
while True:
|
83 |
+
time.sleep(5) # Update every 5 seconds
|
84 |
+
status = "Model is loaded and ready." if model_loaded else "Model is not loaded."
|
85 |
+
status_text.update(value=status)
|
86 |
+
|
87 |
# Gradio Interface
|
88 |
with gr.Blocks() as demo:
|
89 |
gr.Markdown("# DeepSeek-R1 Chatbot")
|
|
|
100 |
|
101 |
status_text = gr.Textbox(label="Model Status", value="Model not loaded yet.", interactive=False)
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
def respond(message, chat_history):
|
104 |
bot_message = chat(message, chat_history)
|
105 |
chat_history.append((message, bot_message))
|
|
|
109 |
clear_button.click(lambda: [], None, chatbot)
|
110 |
reload_button.click(reload_model_button, None, status_text)
|
111 |
|
112 |
+
# Start a background thread to update the status text periodically
|
113 |
+
threading.Thread(target=update_status_periodically, args=(status_text,), daemon=True).start()
|
114 |
|
115 |
# Load the model when the server starts
|
116 |
if __name__ == "__main__":
|
117 |
load_model() # Pre-load the model
|
118 |
+
demo.launch(server_name="0.0.0.0")
|