Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,9 +6,9 @@ from functools import lru_cache
|
|
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"
|
10 |
src="huggingface", # Changed from transformers_gradio.registry
|
11 |
-
api_name="chat"
|
12 |
)
|
13 |
|
14 |
# Load all models at startup
|
@@ -21,31 +21,32 @@ MODELS = {
|
|
21 |
# --- Chatbot function ---
|
22 |
def chatbot(input_text, history, model_choice, system_message, max_new_tokens, temperature, top_p):
|
23 |
history = history or []
|
24 |
-
|
25 |
# Get the selected model component
|
26 |
model_component = MODELS[model_choice]
|
27 |
-
|
28 |
# Create payload for the model
|
29 |
-
payload =
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
# Run inference using the selected model
|
39 |
try:
|
40 |
-
response = model_component(payload)
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
except Exception as e:
|
46 |
assistant_response = f"Error: {str(e)}"
|
47 |
-
|
48 |
-
|
|
|
|
|
49 |
return history, history, ""
|
50 |
|
51 |
# --- Gradio Interface ---
|
|
|
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 |
|
14 |
# Load all models at startup
|
|
|
21 |
# --- Chatbot function ---
|
22 |
def chatbot(input_text, history, model_choice, system_message, max_new_tokens, temperature, top_p):
|
23 |
history = history or []
|
24 |
+
|
25 |
# Get the selected model component
|
26 |
model_component = MODELS[model_choice]
|
27 |
+
|
28 |
# Create payload for the model
|
29 |
+
payload = {
|
30 |
+
"messages": [{"role": "user", "content": input_text}],
|
31 |
+
"system": system_message,
|
32 |
+
"max_tokens": max_new_tokens,
|
33 |
+
"temperature": temperature,
|
34 |
+
"top_p": top_p
|
35 |
+
}
|
36 |
+
|
|
|
37 |
# Run inference using the selected model
|
38 |
try:
|
39 |
+
response = model_component(payload) # The response is likely a dictionary
|
40 |
+
if isinstance(response, dict) and "choices" in response:
|
41 |
+
assistant_response = response["choices"][0]["message"]["content"]
|
42 |
+
else:
|
43 |
+
assistant_response = "Unexpected model response format."
|
44 |
except Exception as e:
|
45 |
assistant_response = f"Error: {str(e)}"
|
46 |
+
|
47 |
+
# Append user and assistant messages to history
|
48 |
+
history.append((input_text, assistant_response))
|
49 |
+
|
50 |
return history, history, ""
|
51 |
|
52 |
# --- Gradio Interface ---
|