jonaschua commited on
Commit
402ce74
·
verified ·
1 Parent(s): 4ce392f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -27
app.py CHANGED
@@ -80,40 +80,37 @@ def choose_model(model_name):
80
  @spaces.GPU(duration=duration)
81
  def respond(message, history: list[tuple[str, str]], model, system_message, max_tokens, temperature, top_p):
82
 
83
- print(model)
84
- model_name = choose_model(model)
85
-
86
- client = InferenceClient(model_name, provider=provider, token=os.getenv('deepseekv2'))
87
 
88
- messages = [{"role": "system", "content": system_message}]
89
-
90
- for val in history:
91
- if val[0]:
92
- messages.append({"role": "user", "content": val[0]})
93
- if val[1]:
94
- messages.append({"role": "assistant", "content": val[1]})
95
-
96
- messages.append({"role": "user", "content": message})
97
-
98
- response = ""
99
-
100
- for message in client.chat_completion(messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p):
101
- token = message.choices[0].delta.content
102
-
103
- response += token
104
- yield response
 
 
105
 
106
 
107
 
108
 
109
  demo = gr.ChatInterface(
110
 
111
- if mode=="text-to-text":
112
- respond,
113
- multimodal=False,
114
- else:
115
- respond,
116
- multimodal=True,
117
  stop_btn = "Stop generation",
118
  # multimodal = True,
119
  title="Ask me anything",
 
80
  @spaces.GPU(duration=duration)
81
  def respond(message, history: list[tuple[str, str]], model, system_message, max_tokens, temperature, top_p):
82
 
83
+ if mode=="text-to-text":
84
+ print(model)
85
+ model_name = choose_model(model)
 
86
 
87
+ client = InferenceClient(model_name, provider=provider, token=os.getenv('deepseekv2'))
88
+
89
+ messages = [{"role": "system", "content": system_message}]
90
+
91
+ for val in history:
92
+ if val[0]:
93
+ messages.append({"role": "user", "content": val[0]})
94
+ if val[1]:
95
+ messages.append({"role": "assistant", "content": val[1]})
96
+
97
+ messages.append({"role": "user", "content": message})
98
+
99
+ response = ""
100
+
101
+ for message in client.chat_completion(messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p):
102
+ token = message.choices[0].delta.content
103
+
104
+ response += token
105
+ yield response
106
 
107
 
108
 
109
 
110
  demo = gr.ChatInterface(
111
 
112
+ respond,
113
+ multimodal=True,
 
 
 
 
114
  stop_btn = "Stop generation",
115
  # multimodal = True,
116
  title="Ask me anything",