Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
#
|
|
|
|
|
|
|
|
|
|
| 4 |
custom_theme = gr.themes.Soft(
|
| 5 |
primary_hue="yellow",
|
| 6 |
secondary_hue="blue",
|
|
@@ -23,20 +26,23 @@ def predict(message, history):
|
|
| 23 |
# Системная инструкция
|
| 24 |
system_prompt = "Тебя зовут Gemini."
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
client = gr.load("models/moonshotai/Kimi-K2-Thinking", provider="novita")
|
| 28 |
-
|
| 29 |
full_query = f"{system_prompt}\n\nПользователь: {message}"
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
# В Gradio 6.0 fill_height лучше указывать в самом Blocks, если launch его не принимает
|
| 33 |
with gr.Blocks(theme=custom_theme, css=css, fill_height=True) as demo:
|
| 34 |
with gr.Sidebar(elem_id="side-bar"):
|
| 35 |
gr.Markdown("# **FlareAI**")
|
| 36 |
gr.Markdown("Flare — твой персональный ассистент")
|
|
|
|
| 37 |
button = gr.LoginButton("Войти")
|
| 38 |
|
| 39 |
gr.ChatInterface(fn=predict)
|
| 40 |
|
| 41 |
-
# Оставляем запуск максимально простым
|
| 42 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# Инициализируем модель один раз вне функции
|
| 4 |
+
# Это исправит ошибку при генерации ответа
|
| 5 |
+
model_client = gr.load("models/moonshotai/Kimi-K2-Thinking", provider="novita")
|
| 6 |
+
|
| 7 |
custom_theme = gr.themes.Soft(
|
| 8 |
primary_hue="yellow",
|
| 9 |
secondary_hue="blue",
|
|
|
|
| 26 |
# Системная инструкция
|
| 27 |
system_prompt = "Тебя зовут Gemini."
|
| 28 |
|
| 29 |
+
# Объединяем системную инструкцию и сообщение
|
|
|
|
|
|
|
| 30 |
full_query = f"{system_prompt}\n\nПользователь: {message}"
|
| 31 |
+
|
| 32 |
+
# Вызываем уже созданный клиент
|
| 33 |
+
try:
|
| 34 |
+
response = model_client(full_query)
|
| 35 |
+
return response
|
| 36 |
+
except Exception as e:
|
| 37 |
+
return f"Ошибка связи с моделью: {str(e)}"
|
| 38 |
|
|
|
|
| 39 |
with gr.Blocks(theme=custom_theme, css=css, fill_height=True) as demo:
|
| 40 |
with gr.Sidebar(elem_id="side-bar"):
|
| 41 |
gr.Markdown("# **FlareAI**")
|
| 42 |
gr.Markdown("Flare — твой персональный ассистент")
|
| 43 |
+
# Кнопка входа важна, если Space требует авторизации для доступа к API
|
| 44 |
button = gr.LoginButton("Войти")
|
| 45 |
|
| 46 |
gr.ChatInterface(fn=predict)
|
| 47 |
|
|
|
|
| 48 |
demo.launch()
|