Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,18 @@
|
|
1 |
|
2 |
-
import streamlit as st
|
3 |
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
4 |
|
5 |
-
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
model = GPT2LMHeadModel.from_pretrained(MODEL_NAME)
|
10 |
-
return model, tokenizer
|
11 |
|
12 |
-
def
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
if prompt:
|
23 |
-
with st.spinner("Generieren von Text..."):
|
24 |
-
generated_text = generate_text(prompt, model, tokenizer)
|
25 |
-
st.header("Generierter Text:")
|
26 |
-
for i, text in enumerate(generated_text):
|
27 |
-
st.subheader(f"Option {i+1}:")
|
28 |
-
st.write(text)
|
|
|
1 |
|
|
|
2 |
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
3 |
|
4 |
+
class EinfachPrompt:
|
5 |
+
def __init__(self):
|
6 |
+
self.tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
7 |
+
self.model = GPT2LMHeadModel.from_pretrained("gpt2")
|
|
|
|
|
8 |
|
9 |
+
def generate(self, prompt):
|
10 |
+
inputs = self.tokenizer.encode(prompt, return_tensors="pt")
|
11 |
+
outputs = self.model.generate(inputs, max_length=150, num_return_sequences=1, temperature=0.7)
|
12 |
+
generated = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
13 |
+
return generated
|
14 |
|
15 |
+
if __name__ == "__main__":
|
16 |
+
einfach_prompt = EinfachPrompt()
|
17 |
+
prompt = "Erzähl mir etwas über EinfachPrompt."
|
18 |
+
print(einfach_prompt.generate(prompt))
|
|
|
|
|
|
|
|
|
|
|
|
|
|