TNK21 commited on
Commit
7ed7214
·
1 Parent(s): cc1a82b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -38
app.py CHANGED
@@ -1,47 +1,33 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load the sentiment analysis and named entity recognition pipelines
5
- sentiment_analysis = pipeline("sentiment-analysis")
6
- ner = pipeline("ner")
7
-
8
- # Create a Gradio interface
9
- def generate_story(user_input):
10
- # Analyze the sentiment of the user's input
11
- sentiment_result = sentiment_analysis(user_input)[0]
12
-
13
- # Identify named entities in the user's input
14
- named_entities = ner(user_input)
15
-
16
- # Generate the story based on user input, sentiment, and named entities
17
- story = f"You seem to be feeling {sentiment_result['label'].lower()}.\n"
18
-
19
- if named_entities:
20
- story += "I noticed the following entities in your input:\n"
21
- for entity in named_entities:
22
- story += f"- {entity['word']} ({entity['entity']})\n"
23
-
24
- story += "Once upon a time..."
25
-
26
- return story
27
-
28
- # Define example inputs for the interface
29
- example_inputs = ["I love ice cream",
30
- "Tell me about Apple Inc.",
31
- "Explain the concept of quantum physics",
32
- "What is the capital of France?",
33
- "Who is the CEO of Microsoft?",
34
- "What is the population of New York City?"]
35
-
36
- # Create the Gradio interface with examples
37
  iface = gr.Interface(
38
  fn=generate_story,
39
- inputs=gr.components.Textbox(label="Enter your input"),
40
- outputs=gr.components.Textbox(label="Generated Story"),
41
- live=True,
 
42
  examples=example_inputs,
43
- title="Interactive Story Generator",
44
- description="Enter your input, and we will generate an interactive story for you."
45
  )
46
 
47
  # Launch the interface
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load the text generation model
5
+ text_generator = pipeline("text-generation", model="gpt2")
6
+
7
+ # Define the function for story generation
8
+ def generate_story(prompt):
9
+ # Generate a story based on the user's prompt
10
+ generated_text = text_generator(prompt, max_length=200, num_return_sequences=1)[0]['generated_text']
11
+ return generated_text
12
+
13
+ # Define example inputs for the Gradio interface
14
+ example_inputs = [
15
+ "Once upon a time, there was a young boy who lived in a small village.",
16
+ "The sun was setting over the horizon, casting a warm glow over the city.",
17
+ "In a galaxy far, far away, a group of rebels were planning their next move.",
18
+ "The door creaked open, revealing a dark and mysterious room.",
19
+ "The clock struck midnight, and the old house came to life.",
20
+ "The wind howled through the trees, as the storm raged on."
21
+ ]
22
+
23
+ # Create a Gradio interface with examples
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  iface = gr.Interface(
25
  fn=generate_story,
26
+ inputs="text",
27
+ outputs="text",
28
+ title="Story Generator",
29
+ description="Enter a prompt to generate a story.",
30
  examples=example_inputs,
 
 
31
  )
32
 
33
  # Launch the interface