Spaces:
Runtime error
Runtime error
Download app.py from abdo-mahde/Orizon: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/spaces/abdo-mahde/Orizon/resolve/main/app.py
- Command line
-
hf download hf://spaces/abdo-mahde/Orizon/app.py
-
curl -L -o app.py https://huggingface.co/spaces/abdo-mahde/Orizon/resolve/main/app.py
1.23 kB
| import os | |
| import gradio as gr | |
| from openai import OpenAI | |
| # التأكد من وجود المفتاح | |
| api_key = os.environ.get("GROQ_API_KEY") | |
| client = OpenAI( | |
| base_url="https://api.groq.com/openai/v1", | |
| api_key=api_key | |
| ) | |
| def chat_response(message, history): | |
| messages = [{"role": "system", "content": "أنت Orizon، مساعد ذكي فخم وسريع."}] | |
| for user, assistant in history: | |
| messages.append({"role": "user", "content": user}) | |
| messages.append({"role": "assistant", "content": assistant}) | |
| messages.append({"role": "user", "content": message}) | |
| response = client.chat.completions.create( | |
| model="llama3-8b-8192", | |
| messages=messages, | |
| stream=True | |
| ) | |
| partial_text = "" | |
| for chunk in response: | |
| if chunk.choices[0].delta.content: | |
| partial_text += chunk.choices[0].delta.content | |
| yield partial_text | |
| # واجهة بسيطة جداً لضمان عدم حدوث تعارض | |
| demo = gr.ChatInterface( | |
| fn=chat_response, | |
| title="Orizon AI", | |
| multimodal=False # هذا السطر يمنع البوت من طلب مكتبات الصوت والصور المعقدة | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |