Spaces:
Runtime error
Runtime error
File size: 2,116 Bytes
ec11884 8abd7cb ec11884 8abd7cb 549f4f9 ec11884 549f4f9 8abd7cb 549f4f9 8abd7cb ec11884 549f4f9 8abd7cb 549f4f9 ec11884 549f4f9 ec11884 549f4f9 ec11884 549f4f9 ec11884 8abd7cb ec11884 549f4f9 ec11884 549f4f9 ec11884 549f4f9 ec11884 549f4f9 ec11884 8abd7cb 549f4f9 8abd7cb 549f4f9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
import gradio as gr
from huggingface_hub import InferenceClient
# Use Arabic-optimized model
client = InferenceClient("aubmindlab/aragpt2-base")
def respond(
message: str,
history: list[list[str]], # Updated format
system_message="أنت مساعد مفيد يتحدث العربية",
max_tokens=512,
temperature=0.7,
top_p=0.95,
):
# Force Arabic responses
prompt = f"باللغة العربية: {message}"
# Format history in messages format
messages = [{"role": "system", "content": system_message}]
for user_msg, bot_msg in history:
if user_msg:
messages.append({"role": "user", "content": user_msg})
if bot_msg:
messages.append({"role": "assistant", "content": bot_msg})
messages.append({"role": "user", "content": prompt})
# Generate Arabic response
response = ""
for chunk in client.text_generation(
prompt=prompt,
max_new_tokens=max_tokens,
stream=True,
temperature=temperature,
repetition_penalty=1.2,
):
response += chunk
yield response
# Mobile-optimized Arabic interface
demo = gr.ChatInterface(
respond,
additional_inputs=[
gr.Textbox(value="أنت مساعد عربي مفيد", label="الرسالة النظام"),
gr.Slider(minimum=1, maximum=512, value=256, label="الحد الأقصى للكلمات"),
gr.Slider(minimum=0.1, maximum=1.0, value=0.5, label="الابتكار"),
gr.Slider(minimum=0.1, maximum=1.0, value=0.9, label="الدقة"),
],
css="""
.gradio-container {direction: rtl;}
textarea {font-family: 'Amiri', serif;}
""",
examples=[
["ما هو أفضل حل للزراعة في السودان؟"], # Sudan example
["كيف يمكن تطوير الذكاء الاصطناعي في السعودية؟"] # KSA example
]
)
if __name__ == "__main__":
# Correct launch parameters
demo.launch(
share=False, # Set to True for temporary public link
auth=("user", "pass") # Optional basic auth
) |