Alfasign commited on
Commit
9493940
1 Parent(s): 14d4b3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -1,3 +1,24 @@
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- gr.Interface.load("models/nomic-ai/gpt4all-13b-snoozy").launch()
 
1
+
2
  import gradio as gr
3
+ import torch
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM
5
+
6
+ def generate_text(prompt, style):
7
+ model_name = "nomic-ai/gpt4all-13b-snoozy"
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
9
+ model = AutoModelForCausalLM.from_pretrained(model_name)
10
+
11
+ full_prompt = f"{prompt} Schreibe die Antwort im Stil von {style}."
12
+ inputs = tokenizer.encode(full_prompt, return_tensors='pt')
13
+ outputs = model.generate(inputs, max_length=150, num_return_sequences=1, no_repeat_ngram_size=2)
14
+
15
+ generated = outputs[:,inputs.shape[-1]:]
16
+ result = tokenizer.decode(generated[0], skip_special_tokens=True)
17
+
18
+ return result
19
+
20
+ styles = ["eine formelle E-Mail", "eine Kurzgeschichte", "ein Gedicht", "ein wissenschaftlicher Bericht", "eine Zeitungsartikel"]
21
+
22
+ iface = gr.Interface(fn=generate_text, inputs=["textbox", gr.inputs.Dropdown(choices=styles)], outputs="text")
23
+ iface.launch()
24