ruslanmv commited on
Commit
3b082f7
·
verified ·
1 Parent(s): ab40b57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -21
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"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,32 +21,31 @@ 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
- "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 ---
 
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"huggingface/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
+ history, # Pass the entire history
31
+ input_text,
32
+ system_message,
33
+ max_new_tokens,
34
+ temperature,
35
+ top_p
36
+ ]
37
+
38
  # Run inference using the selected model
39
  try:
40
+ response = model_component(payload) # the response now it is a tuple containing the updated history as the first element and the generated text as the second
41
+ updated_history, assistant_response = response[0], response[1]
42
+
43
+ history = updated_history
44
+
45
  except Exception as e:
46
  assistant_response = f"Error: {str(e)}"
47
+ history.append((input_text, assistant_response))
48
+
 
 
49
  return history, history, ""
50
 
51
  # --- Gradio Interface ---