Update app.py
Browse files
app.py
CHANGED
@@ -1,74 +1,18 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
from PIL import Image
|
5 |
-
from diffusers import StableDiffusionPipeline
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
generator = pipeline("text-generation", model="gpt2")
|
15 |
|
16 |
-
|
17 |
-
"""
|
18 |
-
Generates a story based on user input.
|
19 |
-
|
20 |
-
Args:
|
21 |
-
prompt: A string containing the starting prompt for the story.
|
22 |
-
|
23 |
-
Returns:
|
24 |
-
A string containing the generated story.
|
25 |
-
"""
|
26 |
-
story = generator(prompt, max_length=1024)[0]["generated_text"]
|
27 |
-
return story
|
28 |
-
|
29 |
-
def generate_image(prompt):
|
30 |
-
"""
|
31 |
-
Generates an image based on user input.
|
32 |
-
|
33 |
-
Args:
|
34 |
-
prompt: A string containing the description for the image.
|
35 |
-
|
36 |
-
Returns:
|
37 |
-
A PIL Image object.
|
38 |
-
"""
|
39 |
-
image = sd_pipeline(prompt).images[0]
|
40 |
-
return image
|
41 |
-
|
42 |
-
# Streamlit app
|
43 |
-
st.title("Hugging Face Storytelling App")
|
44 |
-
|
45 |
-
# Prompt input
|
46 |
-
prompt = st.text_input("Start your story with...")
|
47 |
-
|
48 |
-
# Text-to-speech button
|
49 |
-
if st.button("Speak the Story"):
|
50 |
-
with st.spinner("Speaking the story..."):
|
51 |
-
tts_model.speak(generate_story(prompt))
|
52 |
-
|
53 |
-
# Text-to-text button
|
54 |
-
if st.button("Generate Text from Prompt"):
|
55 |
-
with st.spinner("Generating text..."):
|
56 |
-
new_text = generate_story(prompt)
|
57 |
-
st.write(new_text)
|
58 |
-
|
59 |
-
# Text-to-image button
|
60 |
-
if st.button("Generate Image from Prompt"):
|
61 |
-
with st.spinner("Generating image..."):
|
62 |
-
image = generate_image(prompt)
|
63 |
-
st.image(image)
|
64 |
-
|
65 |
-
# Questions to answer
|
66 |
-
st.write("**Think about your story and answer these questions:**")
|
67 |
-
st.text_input("What is the main character's name?")
|
68 |
-
st.text_input("Where does the story take place?")
|
69 |
-
st.text_input("What is the problem the character faces?")
|
70 |
-
st.text_input("How does the character solve the problem?")
|
71 |
-
|
72 |
-
# Disclaimer
|
73 |
-
st.write("* This app is still under development and may not always generate accurate or coherent results.")
|
74 |
-
st.write("* Please be mindful of the content generated by the AI models.")
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import time
|
|
|
|
|
4 |
|
5 |
+
with gr.Blocks() as demo:
|
6 |
+
chatbot = gr.Chatbot()
|
7 |
+
msg = gr.Textbox()
|
8 |
+
clear = gr.ClearButton([msg, chatbot])
|
9 |
|
10 |
+
def respond(message, chat_history):
|
11 |
+
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
12 |
+
chat_history.append((message, bot_message))
|
13 |
+
time.sleep(2)
|
14 |
+
return "", chat_history
|
15 |
|
16 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
|
|
17 |
|
18 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|