Spaces:
Runtime error
Runtime error
NadaAljohani
commited on
Commit
•
32982c5
1
Parent(s):
3c4377b
Update app.py
Browse files
app.py
CHANGED
@@ -7,19 +7,21 @@ def generate_story(title, model_name):
|
|
7 |
generator = pipeline('text-generation', model=model_name)
|
8 |
# Generate the story based on the input title
|
9 |
story = generator(title,
|
10 |
-
max_length=
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
# Return the generated text
|
15 |
return story[0]['generated_text']
|
16 |
-
|
17 |
# Create the Gradio interface using gr.Interface
|
18 |
demo = gr.Interface(
|
19 |
fn=generate_story, # The function to run
|
20 |
inputs=[ # Inputs for the interface
|
21 |
gr.Textbox(label="Enter Story Title", placeholder="Type a title here..."), # Title input
|
22 |
-
gr.Dropdown(choices=['gpt2', 'gpt2-
|
|
|
23 |
value='gpt2',
|
24 |
label="Choose Model") # Model selection input
|
25 |
],
|
|
|
7 |
generator = pipeline('text-generation', model=model_name)
|
8 |
# Generate the story based on the input title
|
9 |
story = generator(title,
|
10 |
+
max_length=230, # Set the maximum length for the generated text (story) to 230 tokens
|
11 |
+
no_repeat_ngram_size=3, # Avoid repeating any sequence of 3 words (to prevent repetitive text)
|
12 |
+
temperature=0.8, # Introduce some randomness; higher values make the output more random, lower makes it more deterministic
|
13 |
+
top_p=0.95 # Use nucleus sampling (top-p sampling) to focus on the top 95% of probable words, making the text more coherent
|
14 |
+
)
|
15 |
# Return the generated text
|
16 |
return story[0]['generated_text']
|
17 |
+
|
18 |
# Create the Gradio interface using gr.Interface
|
19 |
demo = gr.Interface(
|
20 |
fn=generate_story, # The function to run
|
21 |
inputs=[ # Inputs for the interface
|
22 |
gr.Textbox(label="Enter Story Title", placeholder="Type a title here..."), # Title input
|
23 |
+
gr.Dropdown(choices=['gpt2', 'gpt2-large', 'EleutherAI/gpt-neo-2.7B', 'EleutherAI/gpt-j-6B',
|
24 |
+
'maldv/badger-writer-llama-3-8b', 'EleutherAI/gpt-neo-1.3B'],
|
25 |
value='gpt2',
|
26 |
label="Choose Model") # Model selection input
|
27 |
],
|