Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,20 @@
|
|
1 |
-
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
-
#
|
5 |
model_name = "google/flan-t5-small"
|
6 |
-
|
7 |
-
# Загрузка токенизатора и модели
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
10 |
|
11 |
-
#
|
12 |
pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
13 |
|
14 |
-
#
|
15 |
-
def
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
gr.ChatInterface(fn=answer, title="FlareGPT Light").launch()
|
21 |
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
3 |
|
4 |
+
# Используем Flan-T5 для адекватных ответов
|
5 |
model_name = "google/flan-t5-small"
|
|
|
|
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
8 |
|
9 |
+
# Создаём пайплайн
|
10 |
pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
11 |
|
12 |
+
# Логика обработки сообщений
|
13 |
+
def respond(message, history):
|
14 |
+
if not message.strip():
|
15 |
+
return "Напиши что-нибудь!"
|
16 |
+
response = pipe(message, max_new_tokens=100)[0]["generated_text"]
|
17 |
+
return response
|
|
|
18 |
|
19 |
+
# Интерфейс чата
|
20 |
+
gr.ChatInterface(fn=respond, title="FlareGPT Light").launch()
|