| import gradio as gr |
| from huggingface_hub import InferenceClient |
| import os |
|
|
| hf_token = os.getenv("HF_TOKEN") |
|
|
| |
| client = InferenceClient(token=hf_token) |
|
|
| def chat(message, history): |
| if not hf_token: |
| return "❌ Ошибка: HF_TOKEN не найден" |
| |
| try: |
| |
| messages = [ |
| {"role": "user", "content": message} |
| ] |
| |
| response = client.chat_completion( |
| messages=messages, |
| model="mistralai/Mistral-7B-Instruct-v0.3", |
| max_tokens=500, |
| temperature=0.7 |
| ) |
| |
| if response and response.choices: |
| return response.choices[0].message.content |
| else: |
| return "⚠️ Нет ответа от модели" |
| |
| except Exception as e: |
| return f"🔥 {str(e)}" |
|
|
| demo = gr.ChatInterface( |
| fn=chat, |
| title="ЛиА - Диагностика" |
| ) |
|
|
| demo.launch() |