Testys commited on
Commit
998b26e
1 Parent(s): e66ee6d

Let's hope bug gets solve

Browse files
Files changed (1) hide show
  1. main.py +18 -23
main.py CHANGED
@@ -2,49 +2,44 @@ from utils.image_utils import load_image, check_url
2
  from utils.caption_utils import ImageCaptioning
3
  from utils.topic_generation import TopicGenerator
4
  import streamlit as st
5
- import io
6
 
7
  def main():
8
  st.title("TopicGen")
9
- # Create an instance of the TopicGenerator class
 
10
  topic_generator = TopicGenerator()
11
  img_caption = ImageCaptioning()
12
 
13
- # User input
14
  user_input = st.selectbox(label="Text Input or Image Input", options=["Text", "Image", "Image URL"])
 
15
  if user_input == "Text":
16
  text_input = st.text_input(label="Put in your Idea, Let's generate a matching Topic Sentence🤗🤗")
17
- if text_input is not None:
18
  generated_topics = topic_generator.generate_topics(text_input)
19
  for idx, topic in enumerate(generated_topics, 1):
20
  st.write(f"Topic {idx}: {topic}")
21
-
22
  elif user_input == "Image":
23
- img_input = st.file_uploader(label="Drop an Image you have been admiring, Let's see what we can do🤔🤔",
24
- type=["jpg", "png", "jpeg"],
25
- accept_multiple_files=True)
26
- for in_img in img_input:
27
- if in_img is not None:
28
- img = in_img.read()
29
- capt = img_caption.get_caption(img)
30
- st.image(image=img, caption=capt, width=250, height=250)
31
- generated_topics = topic_generator.generate_topics(capt)
32
- for idx, topic in enumerate(generated_topics, 1):
33
- st.write(f"Topic {idx}: {topic}")
34
 
35
  elif user_input == "Image URL":
36
- url_input = st.text_input(label="Do you have a link to the Image you would like to drop, Go Ahead and We got "
37
- "you covered😉😉")
38
- if url_input is not None:
39
- url_img = check_url(url_input)
40
- img_load = load_image(url_img)
41
  caption = img_caption.get_caption(img_load)
42
  st.image(image=img_load, caption=caption, width=250, height=250)
43
- # Generate and display topics
44
  generated_topics = topic_generator.generate_topics(caption)
45
  for idx, topic in enumerate(generated_topics, 1):
46
  st.write(f"Topic {idx}: {topic}")
47
 
48
-
49
  if __name__ == "__main__":
50
  main()
 
 
2
  from utils.caption_utils import ImageCaptioning
3
  from utils.topic_generation import TopicGenerator
4
  import streamlit as st
 
5
 
6
  def main():
7
  st.title("TopicGen")
8
+
9
+ # Load the models just once
10
  topic_generator = TopicGenerator()
11
  img_caption = ImageCaptioning()
12
 
 
13
  user_input = st.selectbox(label="Text Input or Image Input", options=["Text", "Image", "Image URL"])
14
+
15
  if user_input == "Text":
16
  text_input = st.text_input(label="Put in your Idea, Let's generate a matching Topic Sentence🤗🤗")
17
+ if text_input:
18
  generated_topics = topic_generator.generate_topics(text_input)
19
  for idx, topic in enumerate(generated_topics, 1):
20
  st.write(f"Topic {idx}: {topic}")
21
+
22
  elif user_input == "Image":
23
+ img_files = st.file_uploader(label="Drop an Image you have been admiring, Let's see what we can do🤔🤔",
24
+ type=["jpg", "png", "jpeg"], accept_multiple_files=True)
25
+ for img_file in img_files or []:
26
+ img_bytes = img_file.read()
27
+ caption = img_caption.get_caption(img_bytes)
28
+ st.image(image=img_bytes, caption=caption, width=250, height=250)
29
+ generated_topics = topic_generator.generate_topics(caption)
30
+ for idx, topic in enumerate(generated_topics, 1):
31
+ st.write(f"Topic {idx}: {topic}")
 
 
32
 
33
  elif user_input == "Image URL":
34
+ url_input = st.text_input(label="Do you have a link to the Image you would like to drop, Go Ahead and We got you covered😉😉")
35
+ if url_input:
36
+ img_load = load_image(check_url(url_input))
 
 
37
  caption = img_caption.get_caption(img_load)
38
  st.image(image=img_load, caption=caption, width=250, height=250)
 
39
  generated_topics = topic_generator.generate_topics(caption)
40
  for idx, topic in enumerate(generated_topics, 1):
41
  st.write(f"Topic {idx}: {topic}")
42
 
 
43
  if __name__ == "__main__":
44
  main()
45
+