Download app.py from khadijae/hack: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/khadijae/hack/resolve/main/app.py
- Command line
-
hf download hf://spaces/khadijae/hack/app.py
-
curl -L -o app.py https://huggingface.co/spaces/khadijae/hack/resolve/main/app.py
1.45 kB
| import gradio as gr | |
| import requests | |
| import json | |
| # الرابط ديال السيرفر ديالك فـ DigitalOcean | |
| URL = "http://134.199.193.220:8000/v1/chat/completions" | |
| def generate_response(message, history): | |
| payload = { | |
| "model": "meta-llama/Meta-Llama-3-8B-Instruct", | |
| "messages": [ | |
| {"role": "system", "content": "You are a helpful Moroccan assistant. Answer in Moroccan Darija."}, | |
| {"role": "user", "content": message} | |
| ], | |
| "temperature": 0.7, | |
| "max_tokens": 500 | |
| } | |
| headers = {"Content-Type": "application/json"} | |
| try: | |
| response = requests.post(URL, headers=headers, data=json.dumps(payload)) | |
| if response.status_code == 200: | |
| result = response.json() | |
| return result['choices'][0]['message']['content'] | |
| else: | |
| return f"خطأ من السيرفر: {response.status_code}" | |
| except Exception as e: | |
| return f"ماقدرتش نتواصل مع AMD GPU: {str(e)}" | |
| # واجهة الشات | |
| demo = gr.ChatInterface( | |
| fn=generate_response, | |
| title="Sawt AI - Powered by AMD MI300X", | |
| description="هاد المساعد الذكي خدام بأقوى GPU ديال AMD فـ DigitalOcean ومرتبط بـ Hugging Face", | |
| examples=["كيف داير؟", "شنو هي أحسن مدينة فالمغرب؟", "عطيني وصفة ديال الطجين"] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |