Spaces:
Running
Running
Upload 2 files
Browse files- app.py +15 -0
- inference.py +20 -0
app.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from inference import generate
|
3 |
+
examples = [
|
4 |
+
["С помощью круглых тензоров"],
|
5 |
+
["gpt40 это"],
|
6 |
+
]
|
7 |
+
demo = gr.Interface(
|
8 |
+
fn=generate,
|
9 |
+
title="Генератор ебаных идей для резерча.",
|
10 |
+
inputs=gr.inputs.Textbox(lines=5, label="Ввод"),
|
11 |
+
outputs=gr.outputs.Textbox(label="Генерация"),
|
12 |
+
examples=examples
|
13 |
+
)
|
14 |
+
if __name__ == "__main__":
|
15 |
+
demo.launch()
|
inference.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
|
4 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
5 |
+
model_dir = "Den4ikAI/ebany_researcher"
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
8 |
+
tokenizer.add_special_tokens({'bos_token': '<s>', 'eos_token': '</s>', 'pad_token': '<pad>'})
|
9 |
+
|
10 |
+
model = AutoModelForCausalLM.from_pretrained(model_dir)
|
11 |
+
model.to(device)
|
12 |
+
model.eval()
|
13 |
+
def generate(prompt):
|
14 |
+
encoded_prompt = tokenizer.encode(prompt, return_tensors="pt").to(device)
|
15 |
+
out = model.generate(encoded_prompt, max_length=50, do_sample=True, top_k=50, top_p=0.95, temperature=1.0,
|
16 |
+
num_return_sequences=1)
|
17 |
+
for i, tokens in enumerate(out.cpu().tolist(), start=1):
|
18 |
+
tokens = tokens[encoded_prompt.shape[1]:]
|
19 |
+
text = tokenizer.decode(tokens)
|
20 |
+
return text
|