TNK21 commited on
Commit
9e5bfe7
·
1 Parent(s): b0bc39b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Create the Gradio interface
29
+ iface = gr.Interface(
30
+ fn=generate_story,
31
+ inputs=gr.inputs.Textbox("Enter your input"),
32
+ outputs=gr.outputs.Textbox("Generated Story"),
33
+ live=True,
34
+ title="Interactive Story Generator",
35
+ description="Enter your input, and we will generate an interactive story for you."
36
+ )
37
+
38
+ # Launch the interface
39
+ iface.launch()