Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
# Placeholder for model loading (adjust as needed for your specific models)
|
4 |
-
# In a real application, these would load actual models
|
5 |
def load_model(model_name):
|
6 |
-
print(f"Loading {model_name}...")
|
7 |
# Simulate different model behaviors (replace with actual model logic)
|
8 |
if model_name == "DeepSeek-R1-Distill-Qwen-32B":
|
9 |
return lambda input_text, history: f"Distilled Model Response to: {input_text}"
|
@@ -34,44 +33,42 @@ def chatbot(input_text, history, model_choice, system_message, max_new_tokens, t
|
|
34 |
else:
|
35 |
model_function = lambda x, h: "Please select a model."
|
36 |
|
37 |
-
# Simulate model response with parameters
|
38 |
-
# In a real application, you would pass these parameters to your model
|
39 |
response = model_function(input_text, history)
|
40 |
-
response
|
41 |
-
|
42 |
-
|
43 |
-
history.append((input_text, response))
|
44 |
-
return history, history, "" # Update both chatbot output and state
|
45 |
|
|
|
|
|
46 |
|
47 |
# --- Gradio Interface ---
|
48 |
-
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
49 |
gr.Markdown(
|
50 |
"""
|
51 |
# DeepSeek Chatbot
|
52 |
Created by [ruslanmv.com](https://ruslanmv.com/)
|
53 |
-
|
54 |
This is a demo of different DeepSeek models. Select a model, type your message, and click "Submit".
|
55 |
You can also adjust optional parameters like system message, max new tokens, temperature, and top-p.
|
56 |
"""
|
57 |
)
|
58 |
|
59 |
with gr.Row():
|
60 |
-
with gr.Column(
|
61 |
chatbot_output = gr.Chatbot(label="DeepSeek Chatbot", height=500)
|
62 |
msg = gr.Textbox(label="Your Message", placeholder="Type your message here...")
|
63 |
-
|
64 |
with gr.Row():
|
65 |
submit_btn = gr.Button("Submit", variant="primary")
|
66 |
clear_btn = gr.ClearButton([msg, chatbot_output])
|
67 |
-
|
68 |
-
|
|
|
|
|
69 |
model_choice = gr.Radio(
|
70 |
choices=["DeepSeek-R1-Distill-Qwen-32B", "DeepSeek-R1", "DeepSeek-R1-Zero"],
|
71 |
label="Choose a Model",
|
72 |
-
value="DeepSeek-R1"
|
73 |
)
|
74 |
-
|
75 |
with gr.Accordion("Optional Parameters", open=False):
|
76 |
system_message = gr.Textbox(
|
77 |
label="System Message",
|
@@ -87,6 +84,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo: # Apply a theme
|
|
87 |
top_p = gr.Slider(
|
88 |
minimum=0.10, maximum=1.00, value=0.90, label="Top-p (nucleus sampling)"
|
89 |
)
|
|
|
90 |
|
91 |
# Maintain chat history
|
92 |
chat_history = gr.State([])
|
@@ -95,12 +93,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo: # Apply a theme
|
|
95 |
submit_btn.click(
|
96 |
chatbot,
|
97 |
[msg, chat_history, model_choice, system_message, max_new_tokens, temperature, top_p],
|
98 |
-
[chatbot_output, chat_history, msg],
|
99 |
)
|
100 |
msg.submit(
|
101 |
chatbot,
|
102 |
[msg, chat_history, model_choice, system_message, max_new_tokens, temperature, top_p],
|
103 |
-
[chatbot_output, chat_history, msg],
|
104 |
)
|
105 |
|
106 |
# Launch the demo
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
# Placeholder for model loading (adjust as needed for your specific models)
|
|
|
4 |
def load_model(model_name):
|
5 |
+
print(f"Loading {model_name}...")
|
6 |
# Simulate different model behaviors (replace with actual model logic)
|
7 |
if model_name == "DeepSeek-R1-Distill-Qwen-32B":
|
8 |
return lambda input_text, history: f"Distilled Model Response to: {input_text}"
|
|
|
33 |
else:
|
34 |
model_function = lambda x, h: "Please select a model."
|
35 |
|
36 |
+
# Simulate model response with parameters
|
|
|
37 |
response = model_function(input_text, history)
|
38 |
+
# Format the response for display (without parameter details in the main chat)
|
39 |
+
display_response = f"{response}"
|
|
|
|
|
|
|
40 |
|
41 |
+
history.append((input_text, display_response))
|
42 |
+
return history, history, "", model_choice, system_message, max_new_tokens, temperature, top_p # Clear input, keep other parameters
|
43 |
|
44 |
# --- Gradio Interface ---
|
45 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
46 |
gr.Markdown(
|
47 |
"""
|
48 |
# DeepSeek Chatbot
|
49 |
Created by [ruslanmv.com](https://ruslanmv.com/)
|
50 |
+
|
51 |
This is a demo of different DeepSeek models. Select a model, type your message, and click "Submit".
|
52 |
You can also adjust optional parameters like system message, max new tokens, temperature, and top-p.
|
53 |
"""
|
54 |
)
|
55 |
|
56 |
with gr.Row():
|
57 |
+
with gr.Column():
|
58 |
chatbot_output = gr.Chatbot(label="DeepSeek Chatbot", height=500)
|
59 |
msg = gr.Textbox(label="Your Message", placeholder="Type your message here...")
|
|
|
60 |
with gr.Row():
|
61 |
submit_btn = gr.Button("Submit", variant="primary")
|
62 |
clear_btn = gr.ClearButton([msg, chatbot_output])
|
63 |
+
|
64 |
+
# Options moved below the chat interface
|
65 |
+
with gr.Row():
|
66 |
+
with gr.Accordion("Options", open=True): # Changed label to "Options"
|
67 |
model_choice = gr.Radio(
|
68 |
choices=["DeepSeek-R1-Distill-Qwen-32B", "DeepSeek-R1", "DeepSeek-R1-Zero"],
|
69 |
label="Choose a Model",
|
70 |
+
value="DeepSeek-R1"
|
71 |
)
|
|
|
72 |
with gr.Accordion("Optional Parameters", open=False):
|
73 |
system_message = gr.Textbox(
|
74 |
label="System Message",
|
|
|
84 |
top_p = gr.Slider(
|
85 |
minimum=0.10, maximum=1.00, value=0.90, label="Top-p (nucleus sampling)"
|
86 |
)
|
87 |
+
|
88 |
|
89 |
# Maintain chat history
|
90 |
chat_history = gr.State([])
|
|
|
93 |
submit_btn.click(
|
94 |
chatbot,
|
95 |
[msg, chat_history, model_choice, system_message, max_new_tokens, temperature, top_p],
|
96 |
+
[chatbot_output, chat_history, msg, model_choice, system_message, max_new_tokens, temperature, top_p],
|
97 |
)
|
98 |
msg.submit(
|
99 |
chatbot,
|
100 |
[msg, chat_history, model_choice, system_message, max_new_tokens, temperature, top_p],
|
101 |
+
[chatbot_output, chat_history, msg, model_choice, system_message, max_new_tokens, temperature, top_p],
|
102 |
)
|
103 |
|
104 |
# Launch the demo
|