Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,32 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
+
MODEL_NAME = "google/gemma-2-9b-it"
|
| 6 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
+
|
| 8 |
+
client = InferenceClient(
|
| 9 |
+
model=MODEL_NAME,
|
| 10 |
+
token=HF_TOKEN
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
def chat(message, history):
|
| 14 |
+
messages = [{"role": "system", "content": "أنت مساعد ذكي."}]
|
| 15 |
+
|
| 16 |
+
for u, a in history:
|
| 17 |
+
if u:
|
| 18 |
+
messages.append({"role": "user", "content": u})
|
| 19 |
+
if a:
|
| 20 |
+
messages.append({"role": "assistant", "content": a})
|
| 21 |
+
|
| 22 |
+
messages.append({"role": "user", "content": message})
|
| 23 |
+
|
| 24 |
+
response = client.chat_completion(
|
| 25 |
+
messages=messages,
|
| 26 |
+
max_tokens=300
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
return response.choices[0].message["content"]
|
| 30 |
+
|
| 31 |
+
demo = gr.ChatInterface(chat)
|
| 32 |
+
demo.launch()
|