Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Загружаем модель Qwen локально
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-7B", trust_remote_code=True)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-7B", device_map="auto", torch_dtype=torch.float16, trust_remote_code=True)
|
8 |
+
|
9 |
+
def respond(message):
|
10 |
+
inputs = tokenizer(message, return_tensors="pt").to(model.device)
|
11 |
+
outputs = model.generate(**inputs, max_new_tokens=200)
|
12 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
13 |
+
return response
|
14 |
+
|
15 |
+
# Создаём интерфейс
|
16 |
+
gr.Interface(
|
17 |
+
fn=respond,
|
18 |
+
inputs=gr.Textbox(label="Ваше сообщение"),
|
19 |
+
outputs=gr.Textbox(label="Qwen отвечает"),
|
20 |
+
title="Qwen Прокси",
|
21 |
+
description="Это API-прокси для Janotaro.ai"
|
22 |
+
).launch()
|