Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
# Use Arabic-optimized model
|
5 |
-
client = InferenceClient("aubmindlab/aragpt2-base")
|
6 |
|
7 |
def respond(
|
8 |
-
message,
|
9 |
-
history: list[
|
10 |
system_message="أنت مساعد مفيد يتحدث العربية",
|
11 |
max_tokens=512,
|
12 |
temperature=0.7,
|
13 |
top_p=0.95,
|
14 |
):
|
15 |
# Force Arabic responses
|
16 |
-
prompt = f"باللغة العربية: {message}"
|
17 |
|
|
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
|
21 |
-
for user_msg, bot_msg in history[-3:]: # Limit history for mobile performance
|
22 |
if user_msg:
|
23 |
messages.append({"role": "user", "content": user_msg})
|
24 |
if bot_msg:
|
@@ -33,7 +33,7 @@ def respond(
|
|
33 |
max_new_tokens=max_tokens,
|
34 |
stream=True,
|
35 |
temperature=temperature,
|
36 |
-
repetition_penalty=1.2,
|
37 |
):
|
38 |
response += chunk
|
39 |
yield response
|
@@ -58,9 +58,8 @@ demo = gr.ChatInterface(
|
|
58 |
)
|
59 |
|
60 |
if __name__ == "__main__":
|
61 |
-
#
|
62 |
demo.launch(
|
63 |
-
|
64 |
-
|
65 |
-
prevent_thread_lock=True
|
66 |
)
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
# Use Arabic-optimized model
|
5 |
+
client = InferenceClient("aubmindlab/aragpt2-base")
|
6 |
|
7 |
def respond(
|
8 |
+
message: str,
|
9 |
+
history: list[list[str]], # Updated format
|
10 |
system_message="أنت مساعد مفيد يتحدث العربية",
|
11 |
max_tokens=512,
|
12 |
temperature=0.7,
|
13 |
top_p=0.95,
|
14 |
):
|
15 |
# Force Arabic responses
|
16 |
+
prompt = f"باللغة العربية: {message}"
|
17 |
|
18 |
+
# Format history in messages format
|
19 |
messages = [{"role": "system", "content": system_message}]
|
20 |
|
21 |
+
for user_msg, bot_msg in history:
|
|
|
22 |
if user_msg:
|
23 |
messages.append({"role": "user", "content": user_msg})
|
24 |
if bot_msg:
|
|
|
33 |
max_new_tokens=max_tokens,
|
34 |
stream=True,
|
35 |
temperature=temperature,
|
36 |
+
repetition_penalty=1.2,
|
37 |
):
|
38 |
response += chunk
|
39 |
yield response
|
|
|
58 |
)
|
59 |
|
60 |
if __name__ == "__main__":
|
61 |
+
# Correct launch parameters
|
62 |
demo.launch(
|
63 |
+
share=False, # Set to True for temporary public link
|
64 |
+
auth=("user", "pass") # Optional basic auth
|
|
|
65 |
)
|