Update app.py
Browse files
app.py
CHANGED
@@ -198,6 +198,7 @@ def extract_title(text):
|
|
198 |
title = re.sub(r'[^a-zA-Z0-9_\-]', ' ', text[-200:])
|
199 |
return title[-200:]
|
200 |
|
|
|
201 |
def process_image(image_input, user_prompt):
|
202 |
SaveNewFile=True
|
203 |
image_file_name=''
|
@@ -210,7 +211,8 @@ def process_image(image_input, user_prompt):
|
|
210 |
if image_input is None:
|
211 |
data=False
|
212 |
else:
|
213 |
-
image_file_name = image_input.name
|
|
|
214 |
image_input = image_input.read()
|
215 |
SaveNewFile=True
|
216 |
|
@@ -1130,7 +1132,7 @@ def display_glossary(glossary, area):
|
|
1130 |
for idx, term in enumerate(terms, start=1):
|
1131 |
st.write(f"{idx}. {term}")
|
1132 |
|
1133 |
-
|
1134 |
def display_images_and_wikipedia_summaries(num_columns=4):
|
1135 |
image_files = [f for f in os.listdir('.') if f.endswith('.png')]
|
1136 |
if not image_files:
|
@@ -1142,6 +1144,7 @@ def display_images_and_wikipedia_summaries(num_columns=4):
|
|
1142 |
cols = st.columns(num_columns) # Use specified num_columns for layout
|
1143 |
col_index = 0 # Initialize column index for cycling through columns
|
1144 |
|
|
|
1145 |
for image_file in image_files_sorted:
|
1146 |
with cols[col_index % num_columns]: # Cycle through columns based on num_columns
|
1147 |
try:
|
@@ -1152,8 +1155,12 @@ def display_images_and_wikipedia_summaries(num_columns=4):
|
|
1152 |
|
1153 |
# Add text input for image file
|
1154 |
image_text_input = st.text_input(f"Image Prompt for {image_file}", key=f"image_prompt_{image_file}")
|
1155 |
-
if image_text_input:
|
1156 |
-
process_image(
|
|
|
|
|
|
|
|
|
1157 |
except:
|
1158 |
errored = True
|
1159 |
|
@@ -1814,6 +1821,9 @@ def main():
|
|
1814 |
if (image_input is not None):
|
1815 |
image_response = process_image(image_input, text_input)
|
1816 |
|
|
|
|
|
|
|
1817 |
elif option == "Audio":
|
1818 |
text = "You are generating a transcript summary. Create a summary of the provided transcription. Respond in Markdown."
|
1819 |
text_input = st.text_input(label="Enter text prompt to use with Audio context.", value=text)
|
|
|
198 |
title = re.sub(r'[^a-zA-Z0-9_\-]', ' ', text[-200:])
|
199 |
return title[-200:]
|
200 |
|
201 |
+
#@st.cache_resource
|
202 |
def process_image(image_input, user_prompt):
|
203 |
SaveNewFile=True
|
204 |
image_file_name=''
|
|
|
211 |
if image_input is None:
|
212 |
data=False
|
213 |
else:
|
214 |
+
#image_file_name = image_input.name
|
215 |
+
image_file_name = image_input.filename
|
216 |
image_input = image_input.read()
|
217 |
SaveNewFile=True
|
218 |
|
|
|
1132 |
for idx, term in enumerate(terms, start=1):
|
1133 |
st.write(f"{idx}. {term}")
|
1134 |
|
1135 |
+
# Image Prompt
|
1136 |
def display_images_and_wikipedia_summaries(num_columns=4):
|
1137 |
image_files = [f for f in os.listdir('.') if f.endswith('.png')]
|
1138 |
if not image_files:
|
|
|
1144 |
cols = st.columns(num_columns) # Use specified num_columns for layout
|
1145 |
col_index = 0 # Initialize column index for cycling through columns
|
1146 |
|
1147 |
+
errored = False
|
1148 |
for image_file in image_files_sorted:
|
1149 |
with cols[col_index % num_columns]: # Cycle through columns based on num_columns
|
1150 |
try:
|
|
|
1155 |
|
1156 |
# Add text input for image file
|
1157 |
image_text_input = st.text_input(f"Image Prompt for {image_file}", key=f"image_prompt_{image_file}")
|
1158 |
+
if (len(image_text_input) > 0):
|
1159 |
+
#image_response = process_image(image, image_text_input)
|
1160 |
+
image_response = process_image(image_file, image_text_input)
|
1161 |
+
|
1162 |
+
with st.chat_message(name="ai", avatar="🦖"):
|
1163 |
+
st.markdown(image_response)
|
1164 |
except:
|
1165 |
errored = True
|
1166 |
|
|
|
1821 |
if (image_input is not None):
|
1822 |
image_response = process_image(image_input, text_input)
|
1823 |
|
1824 |
+
with st.chat_message(name="ai", avatar="🦖"):
|
1825 |
+
st.markdown(image_response)
|
1826 |
+
|
1827 |
elif option == "Audio":
|
1828 |
text = "You are generating a transcript summary. Create a summary of the provided transcription. Respond in Markdown."
|
1829 |
text_input = st.text_input(label="Enter text prompt to use with Audio context.", value=text)
|