Download Chat.py from MaxKio/Mio-chat: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/MaxKio/Mio-chat/resolve/main/Chat.py
- Command line
-
hf download hf://spaces/MaxKio/Mio-chat/Chat.py
-
curl -L -o Chat.py https://huggingface.co/spaces/MaxKio/Mio-chat/resolve/main/Chat.py
1.19 kB
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| client = InferenceClient("MaxKio/Mio-1.0-Pro") | |
| def generate_text(prompt): | |
| if not prompt.strip(): | |
| return "من فضلك اكتب أمراً أولاً." | |
| try: | |
| response = client.text_generation( | |
| prompt, | |
| max_new_tokens=512, | |
| temperature=0.7, | |
| return_full_text=False | |
| ) | |
| return response | |
| except Exception as e: | |
| return f"خطأ في الاتصال بالنموذج: {str(e)}\nتأكد من أن مسار النموذج متاح للعامة." | |
| # بناء الواجهة - بدون theme هنا | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# <center>واجهة تشغيل نموذج Mio Pro الخفيفة</center>") | |
| with gr.Row(): | |
| input_text = gr.Textbox(label="أدخل أمر الكود الموجه:", lines=5) | |
| output_text = gr.Textbox(label="استجابة النموذج:", lines=7, interactive=False) | |
| submit_btn = gr.Button("إرسال", variant="primary") | |
| submit_btn.click(fn=generate_text, inputs=input_text, outputs=output_text) | |
| if __name__ == "__main__": | |
| demo.launch(theme=gr.themes.Soft()) |