Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
84 |
-
|
85 |
-
|
86 |
-
client = InferenceClient(model_name, provider=provider, token=os.getenv('deepseekv2'))
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
demo = gr.ChatInterface(
|
110 |
|
111 |
-
|
112 |
-
|
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",
|