Update app.py
Browse files
app.py
CHANGED
|
@@ -14,31 +14,33 @@ def respond(
|
|
| 14 |
"""
|
| 15 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 16 |
"""
|
| 17 |
-
# client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
|
| 18 |
client = InferenceClient(token=hf_token.token, model="utter-project/EuroLLM-9B-Instruct")
|
| 19 |
|
| 20 |
messages = [{"role": "system", "content": system_message}]
|
| 21 |
-
|
| 22 |
messages.extend(history)
|
| 23 |
-
|
| 24 |
messages.append({"role": "user", "content": message})
|
| 25 |
|
| 26 |
response = ""
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
"""
|
|
@@ -69,3 +71,4 @@ with gr.Blocks() as demo:
|
|
| 69 |
|
| 70 |
if __name__ == "__main__":
|
| 71 |
demo.launch()
|
|
|
|
|
|
| 14 |
"""
|
| 15 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 16 |
"""
|
|
|
|
| 17 |
client = InferenceClient(token=hf_token.token, model="utter-project/EuroLLM-9B-Instruct")
|
| 18 |
|
| 19 |
messages = [{"role": "system", "content": system_message}]
|
|
|
|
| 20 |
messages.extend(history)
|
|
|
|
| 21 |
messages.append({"role": "user", "content": message})
|
| 22 |
|
| 23 |
response = ""
|
| 24 |
|
| 25 |
+
try:
|
| 26 |
+
for msg in client.chat_completion(
|
| 27 |
+
messages,
|
| 28 |
+
max_tokens=max_tokens,
|
| 29 |
+
stream=True,
|
| 30 |
+
temperature=temperature,
|
| 31 |
+
top_p=top_p,
|
| 32 |
+
):
|
| 33 |
+
choices = msg.choices
|
| 34 |
+
if len(choices) and choices[0].delta.content:
|
| 35 |
+
token = choices[0].delta.content
|
| 36 |
+
response += token
|
| 37 |
+
yield response
|
| 38 |
+
except StopIteration:
|
| 39 |
+
pass
|
| 40 |
+
|
| 41 |
+
# Osigurajte da se uvijek vrati barem jedan rezultat
|
| 42 |
+
if not response:
|
| 43 |
+
yield "Sorry, I couldn't generate a response."
|
| 44 |
|
| 45 |
|
| 46 |
"""
|
|
|
|
| 71 |
|
| 72 |
if __name__ == "__main__":
|
| 73 |
demo.launch()
|
| 74 |
+
# client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
|