Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,12 +6,19 @@ model_name = "gpt2"
|
|
6 |
GPT2Tokenizer.from_pretrained(model_name)
|
7 |
GPT2LMHeadModel.from_pretrained(model_name)
|
8 |
|
9 |
-
# Load the pipeline
|
10 |
-
generator = pipeline(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# Function to generate text
|
13 |
def generate_text(prompt):
|
14 |
-
output = generator(prompt,
|
15 |
return output[0]['generated_text']
|
16 |
|
17 |
# Build the interface
|
@@ -23,5 +30,5 @@ iface = gr.Interface(
|
|
23 |
description="Generate text with AI!"
|
24 |
)
|
25 |
|
26 |
-
# Launch it
|
27 |
iface.launch()
|
|
|
6 |
GPT2Tokenizer.from_pretrained(model_name)
|
7 |
GPT2LMHeadModel.from_pretrained(model_name)
|
8 |
|
9 |
+
# Load the pipeline with additional parameters
|
10 |
+
generator = pipeline(
|
11 |
+
'text-generation',
|
12 |
+
model=model_name,
|
13 |
+
do_sample=True, # Enables sampling for more creative output
|
14 |
+
temperature=0.7, # Controls randomness (0.7 is balanced for creativity and coherence)
|
15 |
+
top_k=50, # Limits the vocabulary to the top 50 most likely tokens
|
16 |
+
max_length=150 # Increased length for longer responses
|
17 |
+
)
|
18 |
|
19 |
# Function to generate text
|
20 |
def generate_text(prompt):
|
21 |
+
output = generator(prompt, num_return_sequences=1)
|
22 |
return output[0]['generated_text']
|
23 |
|
24 |
# Build the interface
|
|
|
30 |
description="Generate text with AI!"
|
31 |
)
|
32 |
|
33 |
+
# Launch it
|
34 |
iface.launch()
|