Alfasign commited on
Commit
9ce6c57
1 Parent(s): e5f351c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -15
app.py CHANGED
@@ -1,19 +1,13 @@
1
- from transformers import AutoModelForSequenceClassification, AutoTokenizer, TextClassificationPipeline
2
 
3
- MODEL_PATH = "results/checkpoint-6000/" # Ändern Sie dies entsprechend
4
 
5
- def load_model():
6
- tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
7
- model = AutoModelForSequenceClassification.from_pretrained(MODEL_PATH)
8
- pipeline = TextClassificationPipeline(model=model, tokenizer=tokenizer)
9
- return pipeline
10
 
11
- def classify_text(text):
12
- pipeline = load_model()
13
- result = pipeline(text)
14
- return result
15
 
16
- if __name__ == "__main__":
17
- text = input("Geben Sie einen Text ein: ")
18
- result = classify_text(text)
19
- print(result)
 
1
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
2
 
3
+ MODEL_NAME = "gpt2" # Ändern Sie dies entsprechend
4
 
5
+ tokenizer = GPT2Tokenizer.from_pretrained(MODEL_NAME)
6
+ model = GPT2LMHeadModel.from_pretrained(MODEL_NAME)
 
 
 
7
 
8
+ prompt = "Was ist künstliche Intelligenz?" # Ändern Sie dies entsprechend
9
+ inputs = tokenizer.encode(prompt, return_tensors="pt")
10
+ outputs = model.generate(inputs, max_length=200, num_return_sequences=5)
 
11
 
12
+ for i, output in enumerate(outputs):
13
+ print(f"Output {i+1}: {tokenizer.decode(output)}")