EmmaL1 commited on
Commit
a4d3132
·
verified ·
1 Parent(s): acf9634

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import part
2
+ import streamlit as st
3
+ from transformers import pipeline
4
+ from PIL import Image
5
+
6
+ # function part
7
+ # image to text
8
+ def img2text(img):
9
+ image_to_text_model = pipeline("image-to-text",
10
+ model="Salesforce/blip-image-captioning-base")
11
+ text = image_to_text_model(img)[0]["generated_text"]
12
+ return text
13
+ st.write(text)
14
+
15
+ # text to story
16
+ def text2story(text):
17
+ text_generation_model = pipeline("text-generation",
18
+ model="meta-llama/Meta-Llama-3-8B")
19
+ story_text = "Once upon a time in a land far, far away"
20
+ generated_story = story_text(story_text,
21
+ max_length=100,
22
+ num_return_sequences=1)
23
+
24
+ return generated_story
25
+ st.write(generated_story)
26
+
27
+ # text to audio
28
+ def text2audio(story_text)
29
+ text_to_speech_model = pipeline("text-to-speech", model="facebook/mms-tts-eng")
30
+ text_to_speak = """
31
+ Hi everyone, I'm going to start with a story now!
32
+ """
33
+ speech_output = text_to_speech_model(text_to_speak)
34
+ print("Text-to-Speech Output:", speech_output)
35
+
36
+ from IPython.display import Audio
37
+ print(text_to_speak)
38
+ st.audio(speech_output['audio'],
39
+ sample_rate=speech_output['sampling_rate'])
40
+
41
+ # main part
42
+ st.set_page_config(page_title="Your Image to Audio Story",
43
+ page_icon="*")
44
+ st.header("Turn Your Image to Audio Story")
45
+ uploaded_file = st.file_uploader("Select an Image...", type=["jpg", "png", "jpeg"])
46
+ if uploaded_file is not None:
47
+ image = Image.open(uploaded_file).convert("RGB")
48
+ st.image(image, caption="Uploaded Image", use_column_width=True)