barunsaha commited on
Commit
5313c46
1 Parent(s): 5490aef

Add sample URLs

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import logging
2
  import os
 
 
3
  import PIL
4
  import requests
5
  import streamlit as st
@@ -52,6 +54,12 @@ SAFETY_SETTINGS = [
52
  }
53
  ]
54
 
 
 
 
 
 
 
55
 
56
  @st.cache_resource
57
  def get_gemini_model():
@@ -87,7 +95,8 @@ def get_image_description(image: PIL.Image) -> str:
87
  load_dotenv()
88
  genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
89
 
90
- st.title('Sys2Doc: Generate Documentation Based on System Diagram')
 
91
 
92
  uploaded_file = st.file_uploader(
93
  'Choose an image file (PNG, JPG, or JPEG) that depicts your system,'
@@ -96,7 +105,10 @@ uploaded_file = st.file_uploader(
96
  )
97
 
98
  st.write('OR provide the URL of the image:')
99
- img_url = st.text_input('URL of the image')
 
 
 
100
  st.markdown('(*If an image is uploaded and a URL is also provided, Sys2Doc will consider the uploaded image*)')
101
 
102
  if uploaded_file is not None or (img_url is not None and len(img_url) > 0):
@@ -115,14 +127,18 @@ if uploaded_file is not None or (img_url is not None and len(img_url) > 0):
115
  file_details = {
116
  'file_name': os.path.basename(img_url),
117
  'file_type': the_img.format,
118
- 'file_info': the_img.info
119
  }
120
 
121
  if the_img.mode in ('RGBA', 'P'):
122
  the_img = the_img.convert('RGB')
123
 
124
  st.header('Image')
125
- st.write(file_details)
 
 
 
 
126
 
127
  st.image(the_img, width=250)
128
  description = get_image_description(the_img)
 
1
  import logging
2
  import os
3
+ import random
4
+
5
  import PIL
6
  import requests
7
  import streamlit as st
 
54
  }
55
  ]
56
 
57
+ SAMPLE_IMAGE_URLS = [
58
+ 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/10/Websocket_connection.png/220px-Websocket_connection.png',
59
+ 'https://assets-global.website-files.com/5ff66329429d880392f6cba2/63fe48adb8834a29a618ce84_148.3.png',
60
+ 'https://media.geeksforgeeks.org/wp-content/uploads/bus1.png',
61
+ ]
62
+
63
 
64
  @st.cache_resource
65
  def get_gemini_model():
 
95
  load_dotenv()
96
  genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
97
 
98
+ st.title('Sys2Doc')
99
+ st.header('Generate Documentation Based on System Diagram')
100
 
101
  uploaded_file = st.file_uploader(
102
  'Choose an image file (PNG, JPG, or JPEG) that depicts your system,'
 
105
  )
106
 
107
  st.write('OR provide the URL of the image:')
108
+ img_url = st.text_input(
109
+ label='URL of the image',
110
+ value=random.choice(SAMPLE_IMAGE_URLS),
111
+ )
112
  st.markdown('(*If an image is uploaded and a URL is also provided, Sys2Doc will consider the uploaded image*)')
113
 
114
  if uploaded_file is not None or (img_url is not None and len(img_url) > 0):
 
127
  file_details = {
128
  'file_name': os.path.basename(img_url),
129
  'file_type': the_img.format,
130
+ # 'file_info': the_img.info
131
  }
132
 
133
  if the_img.mode in ('RGBA', 'P'):
134
  the_img = the_img.convert('RGB')
135
 
136
  st.header('Image')
137
+
138
+ try:
139
+ st.write(file_details)
140
+ except Exception:
141
+ pass
142
 
143
  st.image(the_img, width=250)
144
  description = get_image_description(the_img)