update app.py
Browse files
app.py
CHANGED
@@ -27,10 +27,10 @@ if 'message_content_from_caption' not in st.session_state:
|
|
27 |
st.session_state['message_content_from_caption'] = ''
|
28 |
if 'message_content_from_simplified_text' not in st.session_state:
|
29 |
st.session_state['message_content_from_simplified_text'] = ''
|
30 |
-
if '
|
31 |
-
st.session_state['
|
32 |
-
if '
|
33 |
-
st.session_state['
|
34 |
if 'image_from_caption' not in st.session_state:
|
35 |
st.session_state['image_from_caption'] = None
|
36 |
if 'image_from_simplified_text' not in st.session_state:
|
@@ -181,19 +181,19 @@ with st.expander("Press Text Generation"):
|
|
181 |
# Define radio button options
|
182 |
option = st.radio(
|
183 |
"Choose a Language Model:",
|
184 |
-
('
|
185 |
|
186 |
# Conditional logic based on radio button choice
|
187 |
-
if option == '
|
188 |
-
st.header("
|
189 |
|
190 |
############
|
191 |
-
###
|
192 |
############
|
193 |
|
194 |
headers = {"Authorization": f"Bearer {st.session_state['huggingface_key']}"}
|
195 |
|
196 |
-
|
197 |
config_llm.API_URL,
|
198 |
headers=headers,
|
199 |
)
|
@@ -216,7 +216,7 @@ with st.expander("Press Text Generation"):
|
|
216 |
top_p=top_p,
|
217 |
temperature=temperature,
|
218 |
)
|
219 |
-
stream =
|
220 |
output = ""
|
221 |
for response in stream:
|
222 |
if any([end_token in response.token.text for end_token in [config_llm.EOS_STRING, config_llm.EOT_STRING]]):
|
@@ -227,35 +227,35 @@ with st.expander("Press Text Generation"):
|
|
227 |
return output.strip() # Return the complete output
|
228 |
|
229 |
|
230 |
-
# Button to generate press text from new caption from
|
231 |
-
if st.button("Generate Press Text from New Image Caption with
|
232 |
if st.session_state['new_caption']:
|
233 |
try:
|
234 |
-
st.session_state['
|
235 |
except Exception as e:
|
236 |
st.error(f"An error occurred: {e}")
|
237 |
else:
|
238 |
st.warning("Please ensure a caption is generated.")
|
239 |
|
240 |
# Display the generated press text from new caption
|
241 |
-
if st.session_state['
|
242 |
st.write("Generated Press Text from New Caption of Artwork:")
|
243 |
-
st.write(st.session_state['
|
244 |
|
245 |
# Button to generate press text from simplified text
|
246 |
-
if st.button("Generate Press Text from Simplified Text with
|
247 |
if st.session_state['simplified_text']:
|
248 |
try:
|
249 |
-
st.session_state['
|
250 |
except Exception as e:
|
251 |
st.error(f"An error occurred: {e}")
|
252 |
else:
|
253 |
st.warning("Please ensure simplified text is available.")
|
254 |
|
255 |
# Display the generated press text from simplified text
|
256 |
-
if st.session_state['
|
257 |
st.write("Generated Press Text from Simplified Text:")
|
258 |
-
st.write(st.session_state['
|
259 |
|
260 |
elif option == 'GPT-3.5 Turbo':
|
261 |
st.header("GPT-3.5")
|
@@ -352,8 +352,8 @@ with st.expander("Image Generation"):
|
|
352 |
text_to_use_simp = None
|
353 |
|
354 |
# Check which variable is available and set it to text_to_use
|
355 |
-
if '
|
356 |
-
text_to_use_simp = st.session_state['
|
357 |
elif 'message_content_from_simplified_text' in st.session_state and st.session_state['message_content_from_simplified_text']:
|
358 |
text_to_use_simp = st.session_state['message_content_from_simplified_text']
|
359 |
|
@@ -382,8 +382,8 @@ with st.expander("Image Generation"):
|
|
382 |
# Initialize the variable
|
383 |
text_to_use_cap = None
|
384 |
# Check which variable is available and set it to text_to_use
|
385 |
-
if '
|
386 |
-
text_to_use_cap = st.session_state['
|
387 |
elif 'message_content_from_caption' in st.session_state and st.session_state['message_content_from_caption']:
|
388 |
text_to_use_cap = st.session_state['message_content_from_caption']
|
389 |
|
|
|
27 |
st.session_state['message_content_from_caption'] = ''
|
28 |
if 'message_content_from_simplified_text' not in st.session_state:
|
29 |
st.session_state['message_content_from_simplified_text'] = ''
|
30 |
+
if 'mixtral_from_caption' not in st.session_state:
|
31 |
+
st.session_state['mixtral_from_caption'] = ''
|
32 |
+
if 'mixtral_from_simplified' not in st.session_state:
|
33 |
+
st.session_state['mixtral_from_simplified'] = ''
|
34 |
if 'image_from_caption' not in st.session_state:
|
35 |
st.session_state['image_from_caption'] = None
|
36 |
if 'image_from_simplified_text' not in st.session_state:
|
|
|
181 |
# Define radio button options
|
182 |
option = st.radio(
|
183 |
"Choose a Language Model:",
|
184 |
+
('Mixtral 8x7B', 'GPT-3.5 Turbo'))
|
185 |
|
186 |
# Conditional logic based on radio button choice
|
187 |
+
if option == 'Mixtral 8x7B':
|
188 |
+
st.header("Mixtral 8x7B")
|
189 |
|
190 |
############
|
191 |
+
###Mixtral##
|
192 |
############
|
193 |
|
194 |
headers = {"Authorization": f"Bearer {st.session_state['huggingface_key']}"}
|
195 |
|
196 |
+
client_mixtral = Client(
|
197 |
config_llm.API_URL,
|
198 |
headers=headers,
|
199 |
)
|
|
|
216 |
top_p=top_p,
|
217 |
temperature=temperature,
|
218 |
)
|
219 |
+
stream = client_mixtral.generate_stream(prompt, **generate_kwargs)
|
220 |
output = ""
|
221 |
for response in stream:
|
222 |
if any([end_token in response.token.text for end_token in [config_llm.EOS_STRING, config_llm.EOT_STRING]]):
|
|
|
227 |
return output.strip() # Return the complete output
|
228 |
|
229 |
|
230 |
+
# Button to generate press text from new caption from Mixtral
|
231 |
+
if st.button("Generate Press Text from New Image Caption with Mixtral"):
|
232 |
if st.session_state['new_caption']:
|
233 |
try:
|
234 |
+
st.session_state['mixtral_from_caption'] = run_single_input(st.session_state['new_caption'], config_llm.DEFAULT_SYSTEM_PROMPT)
|
235 |
except Exception as e:
|
236 |
st.error(f"An error occurred: {e}")
|
237 |
else:
|
238 |
st.warning("Please ensure a caption is generated.")
|
239 |
|
240 |
# Display the generated press text from new caption
|
241 |
+
if st.session_state['mixtral_from_caption']:
|
242 |
st.write("Generated Press Text from New Caption of Artwork:")
|
243 |
+
st.write(st.session_state['mixtral_from_caption'])
|
244 |
|
245 |
# Button to generate press text from simplified text
|
246 |
+
if st.button("Generate Press Text from Simplified Text with Mixtral"):
|
247 |
if st.session_state['simplified_text']:
|
248 |
try:
|
249 |
+
st.session_state['mixtral_from_simplified'] = run_single_input(st.session_state['simplified_text'], config_llm.DEFAULT_SYSTEM_PROMPT)
|
250 |
except Exception as e:
|
251 |
st.error(f"An error occurred: {e}")
|
252 |
else:
|
253 |
st.warning("Please ensure simplified text is available.")
|
254 |
|
255 |
# Display the generated press text from simplified text
|
256 |
+
if st.session_state['mixtral_from_simplified']:
|
257 |
st.write("Generated Press Text from Simplified Text:")
|
258 |
+
st.write(st.session_state['mixtral_from_simplified'])
|
259 |
|
260 |
elif option == 'GPT-3.5 Turbo':
|
261 |
st.header("GPT-3.5")
|
|
|
352 |
text_to_use_simp = None
|
353 |
|
354 |
# Check which variable is available and set it to text_to_use
|
355 |
+
if 'mixtral_from_simplified' in st.session_state and st.session_state['mixtral_from_simplified']:
|
356 |
+
text_to_use_simp = st.session_state['mixtral_from_simplified']
|
357 |
elif 'message_content_from_simplified_text' in st.session_state and st.session_state['message_content_from_simplified_text']:
|
358 |
text_to_use_simp = st.session_state['message_content_from_simplified_text']
|
359 |
|
|
|
382 |
# Initialize the variable
|
383 |
text_to_use_cap = None
|
384 |
# Check which variable is available and set it to text_to_use
|
385 |
+
if 'mixtral_from_caption' in st.session_state and st.session_state['mixtral_from_caption']:
|
386 |
+
text_to_use_cap = st.session_state['mixtral_from_caption']
|
387 |
elif 'message_content_from_caption' in st.session_state and st.session_state['message_content_from_caption']:
|
388 |
text_to_use_cap = st.session_state['message_content_from_caption']
|
389 |
|