Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
pip install -r requirements.txt
|
2 |
-
|
3 |
# import part
|
4 |
import streamlit as st
|
5 |
from transformers import pipeline
|
@@ -16,8 +14,11 @@ def img2text(url):
|
|
16 |
|
17 |
# text2story
|
18 |
def text2story(text):
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
21 |
return story_text
|
22 |
|
23 |
# text2audio
|
@@ -30,7 +31,7 @@ def text2audio(story_text):
|
|
30 |
|
31 |
# main part
|
32 |
st.set_page_config(page_title="Your Image to Audio Story",
|
33 |
-
page_icon="🦜")
|
34 |
st.header("Turn Your Image to Audio Story")
|
35 |
|
36 |
# Upload image
|
@@ -46,21 +47,20 @@ if uploaded_file is not None:
|
|
46 |
st.image(uploaded_file, caption="Uploaded Image",
|
47 |
use_column_width=True)
|
48 |
|
49 |
-
#Stage 1: Image to Text
|
50 |
st.text('Processing img2text...')
|
51 |
scenario = img2text(uploaded_file.name)
|
52 |
st.write(scenario)
|
53 |
|
54 |
-
#Stage 2: Text to Story
|
55 |
st.text('Generating a story...')
|
56 |
story = text2story(scenario)
|
57 |
st.write(story)
|
58 |
|
59 |
-
#Stage 3: Story to Audio data
|
60 |
st.text('Generating audio data...')
|
61 |
audio_data = text2audio(story)
|
62 |
|
63 |
# Play button
|
64 |
if st.button("Play Audio"):
|
65 |
-
st.audio(audio_data,
|
66 |
-
format="audio/mpeg")
|
|
|
|
|
|
|
1 |
# import part
|
2 |
import streamlit as st
|
3 |
from transformers import pipeline
|
|
|
14 |
|
15 |
# text2story
|
16 |
def text2story(text):
|
17 |
+
# 创建文本生成的 pipeline 对象
|
18 |
+
story_pipeline = pipeline("text-generation", model="qihoo360/TinyR1-32B-Preview")
|
19 |
+
# 调用 pipeline 生成故事文本,设置最大长度为 200
|
20 |
+
result = story_pipeline(text, max_length=200)
|
21 |
+
story_text = result[0]['generated_text']
|
22 |
return story_text
|
23 |
|
24 |
# text2audio
|
|
|
31 |
|
32 |
# main part
|
33 |
st.set_page_config(page_title="Your Image to Audio Story",
|
34 |
+
page_icon="🦜") # prepare configuration
|
35 |
st.header("Turn Your Image to Audio Story")
|
36 |
|
37 |
# Upload image
|
|
|
47 |
st.image(uploaded_file, caption="Uploaded Image",
|
48 |
use_column_width=True)
|
49 |
|
50 |
+
# Stage 1: Image to Text
|
51 |
st.text('Processing img2text...')
|
52 |
scenario = img2text(uploaded_file.name)
|
53 |
st.write(scenario)
|
54 |
|
55 |
+
# Stage 2: Text to Story
|
56 |
st.text('Generating a story...')
|
57 |
story = text2story(scenario)
|
58 |
st.write(story)
|
59 |
|
60 |
+
# Stage 3: Story to Audio data
|
61 |
st.text('Generating audio data...')
|
62 |
audio_data = text2audio(story)
|
63 |
|
64 |
# Play button
|
65 |
if st.button("Play Audio"):
|
66 |
+
st.audio(audio_data, format="audio/mpeg")
|
|