isom5240 commited on
Commit
8533608
·
verified ·
1 Parent(s): f4f24b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -11
app.py CHANGED
@@ -1,16 +1,34 @@
 
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 +36,8 @@ 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
+
20
+
21
+
22
+ # main part
23
  # App title
24
+ st.title("Assignment")
25
 
26
  # Write some text
27
+ st.write("Image to Story")
28
 
29
  # File uploader for image and audio
30
  uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
31
+
32
 
33
  # Display image with spinner
34
  if uploaded_image is not None:
 
36
  time.sleep(1) # Simulate a delay
37
  image = Image.open(uploaded_image)
38
  st.image(image, caption="Uploaded Image", use_column_width=True)
39
+ caption = generate_image_caption(uploaded_image)
40
+ st.write((f"Generated Caption: {caption}")
41
+
42
 
 
 
 
 
 
43