Spaces:
Runtime error
Runtime error
Commit
·
fb4368a
1
Parent(s):
fe2c928
:(
Browse files:((((
app.py
DELETED
@@ -1,22 +0,0 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
import gradio as gr
|
4 |
-
|
5 |
-
# Initialize tokenizer and model
|
6 |
-
|
7 |
-
import transformers
|
8 |
-
tokenizer = transformers.GPT2Tokenizer.from_pretrained('gpt2')
|
9 |
-
model = GPT2LMHeadModel.from_pretrained('gpt2')
|
10 |
-
|
11 |
-
# Create a function to generate text
|
12 |
-
def generate_text(input_text):
|
13 |
-
# Encode the input text
|
14 |
-
input_ids = tokenizer.encode(input_text, return_tensors='pt')
|
15 |
-
# Generate the output text
|
16 |
-
output_ids = model.generate(input_ids, max_length=50, do_sample=True, top_k=50, top_p=0.95, num_return_sequences=1)
|
17 |
-
# Decode the output text
|
18 |
-
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
19 |
-
return output_text
|
20 |
-
|
21 |
-
# Create the interface
|
22 |
-
gr.Interface(fn=generate_text, inputs="text", outputs="text", title="Chat GPT").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|