Download app.py from Salvar666/Salva2027: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/Salvar666/Salva2027/resolve/main/app.py
- Command line
-
hf download hf://spaces/Salvar666/Salva2027/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Salvar666/Salva2027/resolve/main/app.py
1.02 kB
| import gradio as gr | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline | |
| model_name = "Qwen/Qwen1.5-7B-Chat" # نموذج قوي وممتاز للمحادثة | |
| print("Loading model...") | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype="auto") | |
| pipe = pipeline("text-generation", model=model, tokenizer=tokenizer) | |
| def predict(message, history): | |
| dialogue = "" | |
| for turn in history: | |
| dialogue += f"User: {turn[0]}\nAssistant: {turn[1]}\n" | |
| dialogue += f"User: {message}\nAssistant:" | |
| response = pipe(dialogue, max_new_tokens=500, return_full_text=False) | |
| return response[0]['generated_text'].strip() | |
| demo = gr.ChatInterface( | |
| fn=predict, | |
| title="النموذج الخارق - Advanced AI", | |
| description="واجهة ذكاء اصطناعي متطورة بقدرات تحليل وتوليد عالية.", | |
| theme="soft" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |