Update app.py
Browse files
app.py
CHANGED
@@ -3,20 +3,18 @@ from transformers import pipeline
|
|
3 |
import torch
|
4 |
import logging
|
5 |
|
6 |
-
# Настройка логирования
|
7 |
logging.basicConfig(level=logging.INFO)
|
8 |
logger = logging.getLogger(__name__)
|
9 |
|
10 |
-
|
11 |
-
model_name = "ai-forever/ruGPT-3.5-13B"
|
12 |
try:
|
13 |
logger.info(f"Попытка загрузки модели {model_name}...")
|
14 |
generator = pipeline(
|
15 |
"text-generation",
|
16 |
model=model_name,
|
17 |
-
device=-1,
|
18 |
framework="pt",
|
19 |
-
max_length=150,
|
20 |
truncation=True,
|
21 |
model_kwargs={"torch_dtype": torch.float32}
|
22 |
)
|
@@ -26,7 +24,7 @@ except Exception as e:
|
|
26 |
exit(1)
|
27 |
|
28 |
def respond(message, max_tokens=150, temperature=0.5, top_p=0.8):
|
29 |
-
prompt = f"
|
30 |
try:
|
31 |
logger.info(f"Генерация ответа для: {message}")
|
32 |
outputs = generator(
|
@@ -38,7 +36,11 @@ def respond(message, max_tokens=150, temperature=0.5, top_p=0.8):
|
|
38 |
num_return_sequences=1
|
39 |
)
|
40 |
response = outputs[0]["generated_text"].replace(prompt, "").strip()
|
41 |
-
|
|
|
|
|
|
|
|
|
42 |
except Exception as e:
|
43 |
logger.error(f"Ошибка генерации ответа: {e}")
|
44 |
return f"Ошибка генерации: {e}"
|
@@ -53,7 +55,7 @@ demo = gr.Interface(
|
|
53 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.8, label="Top-p")
|
54 |
],
|
55 |
outputs="text",
|
56 |
-
title="Медицинский чат-бот на базе
|
57 |
theme=gr.themes.Soft()
|
58 |
)
|
59 |
|
|
|
3 |
import torch
|
4 |
import logging
|
5 |
|
|
|
6 |
logging.basicConfig(level=logging.INFO)
|
7 |
logger = logging.getLogger(__name__)
|
8 |
|
9 |
+
model_name = "microsoft/Phi-3-mini-4k-instruct"
|
|
|
10 |
try:
|
11 |
logger.info(f"Попытка загрузки модели {model_name}...")
|
12 |
generator = pipeline(
|
13 |
"text-generation",
|
14 |
model=model_name,
|
15 |
+
device=-1,
|
16 |
framework="pt",
|
17 |
+
max_length=150,
|
18 |
truncation=True,
|
19 |
model_kwargs={"torch_dtype": torch.float32}
|
20 |
)
|
|
|
24 |
exit(1)
|
25 |
|
26 |
def respond(message, max_tokens=150, temperature=0.5, top_p=0.8):
|
27 |
+
prompt = f"You are a medical chatbot. User says: '{message}'. Provide diagnosis and treatment in English."
|
28 |
try:
|
29 |
logger.info(f"Генерация ответа для: {message}")
|
30 |
outputs = generator(
|
|
|
36 |
num_return_sequences=1
|
37 |
)
|
38 |
response = outputs[0]["generated_text"].replace(prompt, "").strip()
|
39 |
+
# Простой перевод (для примера)
|
40 |
+
if "Diagnosis" in response:
|
41 |
+
diagnosis = response.split("Diagnosis:")[1].split("Treatment:")[0].strip()
|
42 |
+
treatment = response.split("Treatment:")[1].strip()
|
43 |
+
response = f"Диагноз: {diagnosis}\nЛечение: {treatment}"
|
44 |
except Exception as e:
|
45 |
logger.error(f"Ошибка генерации ответа: {e}")
|
46 |
return f"Ошибка генерации: {e}"
|
|
|
55 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.8, label="Top-p")
|
56 |
],
|
57 |
outputs="text",
|
58 |
+
title="Медицинский чат-бот на базе Phi-3-mini-4k-instruct",
|
59 |
theme=gr.themes.Soft()
|
60 |
)
|
61 |
|