Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,15 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
temperature,
|
13 |
-
top_p,
|
14 |
-
):
|
15 |
-
# Build prompt from chat history
|
16 |
prompt = system_message.strip() + "\n"
|
17 |
for user_msg, bot_msg in history:
|
18 |
if user_msg:
|
@@ -21,19 +18,18 @@ def respond(
|
|
21 |
prompt += f"المساعد: {bot_msg}\n"
|
22 |
prompt += f"أنت: {message}\nالمساعد:"
|
23 |
|
24 |
-
# Generate response
|
25 |
response = client.text_generation(
|
26 |
-
prompt,
|
27 |
max_new_tokens=max_tokens,
|
28 |
temperature=temperature,
|
29 |
top_p=top_p,
|
30 |
)
|
31 |
-
|
32 |
return response.strip()
|
33 |
|
34 |
-
# Gradio UI
|
35 |
demo = gr.ChatInterface(
|
36 |
-
respond,
|
37 |
additional_inputs=[
|
38 |
gr.Textbox(value="أنت مساعد ذكي ودود يتحدث اللغة العربية.", label="رسالة النظام"),
|
39 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="عدد الرموز القصوى"),
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
from huggingface_hub import InferenceClient
|
4 |
|
5 |
+
# Load Hugging Face token from secrets (set as HF_TOKEN)
|
6 |
+
hf_token = os.getenv("HF_TOKEN")
|
7 |
|
8 |
+
# Arabic Chat model client
|
9 |
+
client = InferenceClient("sambanovasystems/SambaLingo-Arabic-Chat", token=hf_token)
|
10 |
+
|
11 |
+
# Define the response function
|
12 |
+
def respond(message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p):
|
|
|
|
|
|
|
|
|
13 |
prompt = system_message.strip() + "\n"
|
14 |
for user_msg, bot_msg in history:
|
15 |
if user_msg:
|
|
|
18 |
prompt += f"المساعد: {bot_msg}\n"
|
19 |
prompt += f"أنت: {message}\nالمساعد:"
|
20 |
|
21 |
+
# Generate response
|
22 |
response = client.text_generation(
|
23 |
+
prompt=prompt,
|
24 |
max_new_tokens=max_tokens,
|
25 |
temperature=temperature,
|
26 |
top_p=top_p,
|
27 |
)
|
|
|
28 |
return response.strip()
|
29 |
|
30 |
+
# Gradio chat UI
|
31 |
demo = gr.ChatInterface(
|
32 |
+
fn=respond,
|
33 |
additional_inputs=[
|
34 |
gr.Textbox(value="أنت مساعد ذكي ودود يتحدث اللغة العربية.", label="رسالة النظام"),
|
35 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="عدد الرموز القصوى"),
|