Download app.py from DANYALM/LOTUSSAI: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/DANYALM/LOTUSSAI/resolve/main/app.py
- Command line
-
hf download hf://spaces/DANYALM/LOTUSSAI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DANYALM/LOTUSSAI/resolve/main/app.py
1.14 kB
| import os | |
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| MODEL = "HuggingFaceH4/zephyr-7b-beta" # нормальная чат-модель | |
| client = InferenceClient(model=MODEL, token=os.getenv("HF_TOKEN")) | |
| SYSTEM = "Ты дружелюбный ассистент по имени LOTUSS AI. Отвечай кратко и по делу на русском." | |
| def respond(message, history): | |
| # history = список прошлых сообщений, мы их передаем модели | |
| messages = [{"role": "system", "content": SYSTEM}] | |
| for user_msg, bot_msg in history: | |
| messages.append({"role": "user", "content": user_msg}) | |
| messages.append({"role": "assistant", "content": bot_msg}) | |
| messages.append({"role": "user", "content": message}) | |
| # делаем ответ | |
| out = client.chat_completion( | |
| messages=messages, | |
| max_tokens=300, | |
| temperature=0.7, | |
| ) | |
| return out.choices[0].message.content | |
| gr.ChatInterface( | |
| fn=respond, | |
| title="LOTUSS AI (HF)", | |
| description="Настоящий ИИ через Hugging Face Inference API" | |
| ).launch() | |