Spaces:
Build error
Build error
Download app.py from deman2016/deman-gpt1: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/deman2016/deman-gpt1/resolve/main/app.py
- Command line
-
hf download hf://spaces/deman2016/deman-gpt1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/deman2016/deman-gpt1/resolve/main/app.py
1.05 kB
| import gradio as gr | |
| import requests | |
| import os | |
| HF_TOKEN = os.environ.get("HF_TOKEN") | |
| API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1" | |
| HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"} | |
| def chat_with_deman(message): | |
| payload = { | |
| "inputs": f"<s>[INST] {message} [/INST]", | |
| "options": {"wait_for_model": True} | |
| } | |
| response = requests.post(API_URL, headers=HEADERS, json=payload) | |
| if response.status_code == 200: | |
| output = response.json() | |
| try: | |
| return output[0]["generated_text"].split("[/INST]")[1].strip() | |
| except: | |
| return output | |
| else: | |
| return f"❌ تعذر الاتصال بالنموذج: {response.status_code}" | |
| iface = gr.Interface( | |
| fn=chat_with_deman, | |
| inputs=gr.Textbox(lines=2, placeholder="اكتب سؤالك هنا..."), | |
| outputs="text", | |
| title="👑 DEMAN-GPT", | |
| theme="soft", | |
| description="نموذج مطور من فريق DEMAN.STORE | نسخة عبود المطلقة", | |
| ) | |
| iface.launch() | |