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()