Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Inicjalizacja modelu
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("google/gemma-7b-it", device_map="auto", torch_dtype=torch.float16)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b-it")
|
8 |
+
|
9 |
+
def generate_description(prompt):
|
10 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
11 |
+
outputs = model.generate(
|
12 |
+
**inputs,
|
13 |
+
max_new_tokens=100,
|
14 |
+
temperature=0.7,
|
15 |
+
top_p=0.9,
|
16 |
+
repetition_penalty=1.2,
|
17 |
+
do_sample=True
|
18 |
+
)
|
19 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
20 |
+
|
21 |
+
# Interfejs
|
22 |
+
interface = gr.Interface(
|
23 |
+
fn=generate_description,
|
24 |
+
inputs=gr.Textbox(label="Prompt"),
|
25 |
+
outputs=gr.Textbox(label="Generated Description"),
|
26 |
+
title="RPG Battle Descriptions Generator"
|
27 |
+
)
|
28 |
+
|
29 |
+
interface.launch()
|