Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import spaces
|
|
|
|
| 4 |
|
| 5 |
-
@spaces.GPU
|
| 6 |
def respond(
|
| 7 |
message,
|
| 8 |
history: list[dict[str, str]],
|
|
@@ -11,7 +12,9 @@ def respond(
|
|
| 11 |
temperature,
|
| 12 |
top_p,
|
| 13 |
):
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
messages = [{"role": "system", "content": system_message}]
|
| 17 |
messages.extend(history)
|
|
@@ -26,8 +29,7 @@ def respond(
|
|
| 26 |
top_p=top_p,
|
| 27 |
):
|
| 28 |
if msg.choices and msg.choices[0].delta.content:
|
| 29 |
-
|
| 30 |
-
response += token
|
| 31 |
yield response
|
| 32 |
|
| 33 |
chatbot = gr.ChatInterface(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import spaces
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
+
@spaces.GPU
|
| 7 |
def respond(
|
| 8 |
message,
|
| 9 |
history: list[dict[str, str]],
|
|
|
|
| 12 |
temperature,
|
| 13 |
top_p,
|
| 14 |
):
|
| 15 |
+
# استخدم Token من Secrets
|
| 16 |
+
token = os.environ.get("HF_TOKEN")
|
| 17 |
+
client = InferenceClient(model="anaspro/iraqi-kashif-2b", token=token)
|
| 18 |
|
| 19 |
messages = [{"role": "system", "content": system_message}]
|
| 20 |
messages.extend(history)
|
|
|
|
| 29 |
top_p=top_p,
|
| 30 |
):
|
| 31 |
if msg.choices and msg.choices[0].delta.content:
|
| 32 |
+
response += msg.choices[0].delta.content
|
|
|
|
| 33 |
yield response
|
| 34 |
|
| 35 |
chatbot = gr.ChatInterface(
|