Spaces:
Runtime error
Runtime error
File size: 1,033 Bytes
5c99553 2125ddb aaeb012 2125ddb 754dfb0 2125ddb f0f1835 2125ddb 754dfb0 aaeb012 754dfb0 aaeb012 2125ddb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 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() |