Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import huggingface_hub
|
| 3 |
from transformers import pipeline
|
|
|
|
| 4 |
|
|
|
|
| 5 |
generator = pipeline("text-generation", model="distilgpt2")
|
| 6 |
|
|
|
|
| 7 |
def chat_fn(prompt):
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
|
|
|
| 11 |
demo = gr.Interface(
|
| 12 |
fn=chat_fn,
|
| 13 |
-
inputs="
|
| 14 |
-
outputs="
|
| 15 |
title="Eroha AgentAPI — стабильный Space",
|
| 16 |
description="Исправленный runtime с зафиксированной версией huggingface-hub==0.23.4"
|
| 17 |
)
|
| 18 |
|
|
|
|
| 19 |
if __name__ == "__main__":
|
| 20 |
-
# 🟩 ОБЯЗАТЕЛЬНО: пробрасываем наружу сервер
|
| 21 |
demo.launch(
|
| 22 |
-
server_name="0.0.0.0",
|
| 23 |
-
server_port=7860, #
|
| 24 |
-
share=False, #
|
| 25 |
-
show_error=True
|
|
|
|
|
|
|
| 26 |
)
|
| 27 |
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import huggingface_hub
|
| 4 |
|
| 5 |
+
# ====== Настройка модели ======
|
| 6 |
generator = pipeline("text-generation", model="distilgpt2")
|
| 7 |
|
| 8 |
+
# ====== Функция обработки ======
|
| 9 |
def chat_fn(prompt):
|
| 10 |
+
try:
|
| 11 |
+
result = generator(prompt, max_length=60, num_return_sequences=1)[0]["generated_text"]
|
| 12 |
+
return f"🤖 Ответ модели:\n{result}\n\n📦 huggingface-hub версия: {huggingface_hub.__version__}"
|
| 13 |
+
except Exception as e:
|
| 14 |
+
return f"❌ Ошибка: {e}"
|
| 15 |
|
| 16 |
+
# ====== Интерфейс ======
|
| 17 |
demo = gr.Interface(
|
| 18 |
fn=chat_fn,
|
| 19 |
+
inputs=gr.Textbox(label="Введите сообщение"),
|
| 20 |
+
outputs=gr.Textbox(label="Ответ модели"),
|
| 21 |
title="Eroha AgentAPI — стабильный Space",
|
| 22 |
description="Исправленный runtime с зафиксированной версией huggingface-hub==0.23.4"
|
| 23 |
)
|
| 24 |
|
| 25 |
+
# ====== Запуск ======
|
| 26 |
if __name__ == "__main__":
|
|
|
|
| 27 |
demo.launch(
|
| 28 |
+
server_name="0.0.0.0", # слушаем все адреса
|
| 29 |
+
server_port=7860, # порт HF Spaces
|
| 30 |
+
share=False, # не создаём туннель
|
| 31 |
+
show_error=True, # показываем ошибки в консоли
|
| 32 |
+
debug=True, # включаем логирование
|
| 33 |
+
prevent_thread_lock=True # критично для Docker runtime
|
| 34 |
)
|
| 35 |
|