Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import spaces
|
| 3 |
from functools import lru_cache
|
| 4 |
|
| 5 |
# Cache model loading to optimize performance
|
| 6 |
@lru_cache(maxsize=3)
|
| 7 |
def load_hf_model(model_name):
|
|
|
|
| 8 |
return gr.load(
|
| 9 |
name=f"deepseek-ai/{model_name}",
|
| 10 |
-
src="huggingface",
|
| 11 |
api_name="/chat"
|
| 12 |
)
|
| 13 |
|
|
@@ -41,7 +41,8 @@ def chatbot(input_text, history, model_choice, system_message, max_new_tokens, t
|
|
| 41 |
except Exception as e:
|
| 42 |
assistant_response = f"Error: {str(e)}"
|
| 43 |
|
| 44 |
-
history.append(
|
|
|
|
| 45 |
return history, history, ""
|
| 46 |
|
| 47 |
# --- Gradio Interface ---
|
|
@@ -57,8 +58,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Chatbot") as demo:
|
|
| 57 |
|
| 58 |
with gr.Row():
|
| 59 |
with gr.Column():
|
| 60 |
-
|
| 61 |
-
chatbot_output = gr.Chatbot(label="DeepSeek Chatbot", height=500, type="messages")
|
| 62 |
msg = gr.Textbox(label="Your Message", placeholder="Type your message here...")
|
| 63 |
with gr.Row():
|
| 64 |
submit_btn = gr.Button("Submit", variant="primary")
|
|
@@ -101,11 +101,5 @@ with gr.Blocks(theme=gr.themes.Soft(), title="DeepSeek Chatbot") as demo:
|
|
| 101 |
[chatbot_output, chat_history, msg]
|
| 102 |
)
|
| 103 |
|
| 104 |
-
# Remove (or replace) the old `demo.fn = spaces.GPU()(demo.fn)` line
|
| 105 |
-
# If you need GPU acceleration in Spaces, wrap demo.launch() with spaces.GPU()
|
| 106 |
-
# as shown below. Otherwise, remove the spaces.GPU() call.
|
| 107 |
-
|
| 108 |
if __name__ == "__main__":
|
| 109 |
-
|
| 110 |
-
# If you DON'T need GPU from `spaces`, just do: demo.launch()
|
| 111 |
-
spaces.GPU()(demo.launch)()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from functools import lru_cache
|
| 3 |
|
| 4 |
# Cache model loading to optimize performance
|
| 5 |
@lru_cache(maxsize=3)
|
| 6 |
def load_hf_model(model_name):
|
| 7 |
+
# Use the Gradio-built huggingface loader instead of transformers_gradio
|
| 8 |
return gr.load(
|
| 9 |
name=f"deepseek-ai/{model_name}",
|
| 10 |
+
src="huggingface", # Changed from transformers_gradio.registry
|
| 11 |
api_name="/chat"
|
| 12 |
)
|
| 13 |
|
|
|
|
| 41 |
except Exception as e:
|
| 42 |
assistant_response = f"Error: {str(e)}"
|
| 43 |
|
| 44 |
+
history.append({"role": "user", "content": input_text})
|
| 45 |
+
history.append({"role": "assistant", "content": assistant_response})
|
| 46 |
return history, history, ""
|
| 47 |
|
| 48 |
# --- Gradio Interface ---
|
|
|
|
| 58 |
|
| 59 |
with gr.Row():
|
| 60 |
with gr.Column():
|
| 61 |
+
chatbot_output = gr.Chatbot(label="DeepSeek Chatbot", height=500, type='messages')
|
|
|
|
| 62 |
msg = gr.Textbox(label="Your Message", placeholder="Type your message here...")
|
| 63 |
with gr.Row():
|
| 64 |
submit_btn = gr.Button("Submit", variant="primary")
|
|
|
|
| 101 |
[chatbot_output, chat_history, msg]
|
| 102 |
)
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
if __name__ == "__main__":
|
| 105 |
+
demo.launch()
|
|
|
|
|
|