Spaces:
Runtime error
Runtime error
NadaAljohani
commited on
Commit
•
49952d4
1
Parent(s):
16c9dbf
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Function to generate the story
|
5 |
+
def generate_story(title, model_name):
|
6 |
+
# Use text-generation pipeline from Hugging Face
|
7 |
+
generator = pipeline('text-generation', model=model_name)
|
8 |
+
# Generate the story based on the input title
|
9 |
+
story = generator(title,
|
10 |
+
max_length=200, # Fixed max length for the story
|
11 |
+
temperature=0.7, # Fixed temperature for some randomness
|
12 |
+
num_return_sequences=1)
|
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-medium', 'gpt2-large', 'EleutherAI/gpt-neo-2.7B', 'EleutherAI/gpt-j-6B'],
|
23 |
+
value='gpt2',
|
24 |
+
label="Choose Model") # Model selection input
|
25 |
+
],
|
26 |
+
outputs=gr.Textbox(label="Generated Story", lines=10), # Output for the generated story
|
27 |
+
title="AI Story Generator", # Title of the interface
|
28 |
+
description="Enter a title and choose a model to generate a short story" # A short description
|
29 |
+
)
|
30 |
+
|
31 |
+
# Launch the interface
|
32 |
+
demo.launch(share=True)
|