Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
|
4 |
+
# Загрузка токенизатора и модели
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("ai-forever/ruGPT-3.5-13B")
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("ai-forever/ruGPT-3.5-13B")
|
7 |
+
|
8 |
+
# Определение функции для обработки вопроса и генерации ответа
|
9 |
+
def generate_response(question):
|
10 |
+
# Кодирование вопроса в токены
|
11 |
+
input_ids = tokenizer.encode(question, return_tensors="pt")
|
12 |
+
|
13 |
+
# Генерация ответа от модели
|
14 |
+
output = model.generate(input_ids)
|
15 |
+
|
16 |
+
# Декодирование ответа из токенов в текст
|
17 |
+
decoded_output = tokenizer.decode(output[0], skip_special_tokens=True)
|
18 |
+
|
19 |
+
return decoded_output
|
20 |
+
|
21 |
+
# Создание интерфейса Gradio
|
22 |
+
iface = gr.Interface(fn=generate_response, inputs="text", outputs="text")
|
23 |
+
|
24 |
+
# Запуск веб-сайта
|
25 |
+
iface.launch()
|