Spaces:
Runtime error
Runtime error
Download app.py from DORINDESTRES/DOROSfamd: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/DORINDESTRES/DOROSfamd/resolve/main/app.py
- Command line
-
hf download hf://spaces/DORINDESTRES/DOROSfamd/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DORINDESTRES/DOROSfamd/resolve/main/app.py
1.03 kB
| import gradio as gr | |
| import requests | |
| import os | |
| API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-small" | |
| headers = {"Authorization": f"Bearer {os.environ['HF_TOKEN']}"} | |
| def chat(prompt, history=[]): | |
| try: | |
| response = requests.post(API_URL, headers=headers, json={"inputs": prompt}) | |
| result = response.json() | |
| if isinstance(result, list): | |
| answer = result[0]["generated_text"] | |
| else: | |
| answer = result.get("error", "⚠️ Ошибка от модели.") | |
| except Exception as e: | |
| answer = f"⚠️ Ошибка: {str(e)}" | |
| history.append((prompt, answer)) | |
| return history, history | |
| with gr.Blocks(css="body {background-color: #0f1f0f; color: white;}") as demo: | |
| chatbot = gr.Chatbot() | |
| msg = gr.Textbox(placeholder="Введите сообщение и нажмите Enter") | |
| def respond(message, history): | |
| return chat(message, history) | |
| msg.submit(respond, [msg, chatbot], [chatbot, chatbot]) | |
| demo.launch() |