Szeyu commited on
Commit
53b47d5
·
verified ·
1 Parent(s): d116ae3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -12
app.py CHANGED
@@ -1,16 +1,30 @@
 
1
  import streamlit as st
2
  from PIL import Image
3
  import time
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  # App title
6
- st.title("Streamlit Demo on Hugging Face")
7
 
8
  # Write some text
9
- st.write("Welcome to a demo app showcasing basic Streamlit components!")
10
 
11
  # File uploader for image and audio
12
  uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
13
- uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav", "ogg"])
14
 
15
  # Display image with spinner
16
  if uploaded_image is not None:
@@ -18,13 +32,7 @@ if uploaded_image is not None:
18
  time.sleep(1) # Simulate a delay
19
  image = Image.open(uploaded_image)
20
  st.image(image, caption="Uploaded Image", use_column_width=True)
 
 
21
 
22
- # Play audio with spinner
23
- if uploaded_audio is not None:
24
- with st.spinner("Loading audio..."):
25
- time.sleep(1) # Simulate a delay
26
- st.audio(uploaded_audio)
27
-
28
- # Button interaction
29
- if st.button("Click Me"):
30
- st.write("🎉 You clicked the button!")
 
1
+ # Import part
2
  import streamlit as st
3
  from PIL import Image
4
  import time
5
 
6
+ # Function part
7
+ def generate_image_caption(image_path):
8
+ """Generates a caption for the given image using a pre-trained model."""
9
+ img2caption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
10
+ result = img2caption(image_path)
11
+ return result[0]['generated_text']
12
+
13
+ # text2story
14
+ def text2story(text):
15
+ pipe = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
16
+ story_text = pipe(text)[0]['generated_text']
17
+ return story_text
18
+
19
+ # Main part
20
  # App title
21
+ st.title("Assignment")
22
 
23
  # Write some text
24
+ st.write("Image to Story")
25
 
26
  # File uploader for image and audio
27
  uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
 
28
 
29
  # Display image with spinner
30
  if uploaded_image is not None:
 
32
  time.sleep(1) # Simulate a delay
33
  image = Image.open(uploaded_image)
34
  st.image(image, caption="Uploaded Image", use_column_width=True)
35
+ caption = generate_image_caption(uploaded_image)
36
+ st.write(f"Generated Caption: {caption}")
37
 
38
+