Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,13 +10,13 @@ def generate_image_caption(image):
|
|
| 10 |
result = img2caption(image)
|
| 11 |
return result[0]['generated_text']
|
| 12 |
|
| 13 |
-
def text2story(text):
|
| 14 |
-
text_to_story_model = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
| 15 |
-
story_text = text_to_story_model(text, max_new_tokens=150)[0]['generated_text']
|
| 16 |
-
words = story_text.split()
|
| 17 |
-
if len(words) > 100:
|
| 18 |
-
story_text = ' '.join(words[:100]) + '.'
|
| 19 |
-
return story_text
|
| 20 |
|
| 21 |
def text2speech(text):
|
| 22 |
"""Converts text to speech using a pre-trained model."""
|
|
@@ -26,10 +26,10 @@ def text2speech(text):
|
|
| 26 |
|
| 27 |
def main():
|
| 28 |
# App title
|
| 29 |
-
st.title("
|
| 30 |
st.write("Welcome to the image to story audio app!")
|
| 31 |
|
| 32 |
-
uploaded_image = st.file_uploader("Upload an image(jpg, jpeg, png)", type=["jpg", "jpeg", "png"])
|
| 33 |
|
| 34 |
if uploaded_image is not None:
|
| 35 |
image = Image.open(uploaded_image).convert("RGB")
|
|
@@ -50,7 +50,7 @@ def main():
|
|
| 50 |
speech_output = text2speech(story)
|
| 51 |
st.audio(speech_output["audio"], sample_rate=speech_output["sampling_rate"])
|
| 52 |
else:
|
| 53 |
-
st.warning("⚠️
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
| 56 |
main()
|
|
|
|
| 10 |
result = img2caption(image)
|
| 11 |
return result[0]['generated_text']
|
| 12 |
|
| 13 |
+
def text2story(text):
|
| 14 |
+
text_to_story_model = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
| 15 |
+
story_text = text_to_story_model(text, max_new_tokens=150)[0]['generated_text']
|
| 16 |
+
words = story_text.split()
|
| 17 |
+
if len(words) > 100:
|
| 18 |
+
story_text = ' '.join(words[:100]) + '.'
|
| 19 |
+
return story_text
|
| 20 |
|
| 21 |
def text2speech(text):
|
| 22 |
"""Converts text to speech using a pre-trained model."""
|
|
|
|
| 26 |
|
| 27 |
def main():
|
| 28 |
# App title
|
| 29 |
+
st.title("Storyteller on Hugging Face")
|
| 30 |
st.write("Welcome to the image to story audio app!")
|
| 31 |
|
| 32 |
+
uploaded_image = st.file_uploader("Upload an image (jpg, jpeg, png)", type=["jpg", "jpeg", "png"])
|
| 33 |
|
| 34 |
if uploaded_image is not None:
|
| 35 |
image = Image.open(uploaded_image).convert("RGB")
|
|
|
|
| 50 |
speech_output = text2speech(story)
|
| 51 |
st.audio(speech_output["audio"], sample_rate=speech_output["sampling_rate"])
|
| 52 |
else:
|
| 53 |
+
st.warning("⚠️ Please upload an image file")
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
| 56 |
main()
|