Testys commited on
Commit
3bf0da9
1 Parent(s): 8ee32c3

External files for Streamlit

Browse files
Files changed (4) hide show
  1. .gitignore +89 -0
  2. README.md +0 -13
  3. main.py +47 -0
  4. requirements.txt +5 -0
.gitignore ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+
5
+ # C extensions
6
+ *.so
7
+
8
+ # Distribution / packaging
9
+ .Python
10
+ env/
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ *.egg-info/
23
+ .installed.cfg
24
+ *.egg
25
+
26
+ # PyInstaller
27
+ # Usually these files are written by a python script from a template
28
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
29
+ *.manifest
30
+ *.spec
31
+
32
+ # Installer logs
33
+ pip-log.txt
34
+ pip-delete-this-directory.txt
35
+
36
+ # Unit test / coverage reports
37
+ htmlcov/
38
+ .tox/
39
+ .coverage
40
+ .coverage.*
41
+ .cache
42
+ nosetests.xml
43
+ coverage.xml
44
+ *.cover
45
+
46
+ # Translations
47
+ *.mo
48
+ *.pot
49
+
50
+ # Django stuff:
51
+ *.log
52
+
53
+ # Sphinx documentation
54
+ docs/_build/
55
+
56
+ # PyBuilder
57
+ target/
58
+
59
+ # DotEnv configuration
60
+ .env
61
+
62
+ # Database
63
+ *.db
64
+ *.rdb
65
+
66
+ # Pycharm
67
+ .idea
68
+
69
+ # VS Code
70
+ .vscode/
71
+
72
+ # Spyder
73
+ .spyproject/
74
+
75
+ # Jupyter NB Checkpoints
76
+ .ipynb_checkpoints/
77
+
78
+ # exclude data from source control by default
79
+ /data/
80
+
81
+ # Mac OS-specific storage files
82
+ .DS_Store
83
+
84
+ # vim
85
+ *.swp
86
+ *.swo
87
+
88
+ # Mypy cache
89
+ .mypy_cache/
README.md CHANGED
@@ -1,13 +0,0 @@
1
- ---
2
- title: TopicGen
3
- emoji: 🏆
4
- colorFrom: gray
5
- colorTo: gray
6
- sdk: streamlit
7
- sdk_version: 1.26.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
main.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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
+
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
+ generated_topics = topic_generator.generate_topics(text_input)
18
+ for idx, topic in enumerate(generated_topics, 1):
19
+ st.write(f"Topic {idx}: {topic}")
20
+ elif user_input == "Image":
21
+ img_input = st.file_uploader(label="Drop an Image you have been admiring, Let's see what we can do🤔🤔",
22
+ type=["jpg", "png", "jpeg"],
23
+ accept_multiple_files=True)
24
+ for in_img in img_input:
25
+ if in_img is not None:
26
+ img = load_image(in_img)
27
+ capt = img_caption.get_caption(img)
28
+ st.image(image=img, caption=capt, width=250, height=250)
29
+ generated_topics = topic_generator.generate_topics(capt)
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 "
35
+ "you covered😉😉")
36
+ url_img = check_url(url_input)
37
+ img_load = load_image(url_img)
38
+ caption = img_caption.get_caption(img_load)
39
+ st.image(image=img_load, caption=caption, width=250, height=250)
40
+ # Generate and display topics
41
+ generated_topics = topic_generator.generate_topics(caption)
42
+ for idx, topic in enumerate(generated_topics, 1):
43
+ st.write(f"Topic {idx}: {topic}")
44
+
45
+
46
+ if __name__ == "__main__":
47
+ main()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ requests~=2.27.1
2
+ pillow~=9.0.1
3
+ torch
4
+ transformers
5
+ streamlit