Update app.py
Browse files
app.py
CHANGED
@@ -411,120 +411,120 @@ def switch_tab(tab_name):
|
|
411 |
tab1, tab2, tab3 = st.tabs(tabs)
|
412 |
|
413 |
# Tab 1: Introduction
|
414 |
-
if st.session_state.current_tab == tabs[0]:
|
415 |
-
with tab1:
|
416 |
-
# Set up the Streamlit interface
|
417 |
-
col1, col2, col3 = st.columns([1, 4, 1])
|
418 |
-
|
419 |
-
with col1:
|
420 |
-
st.image('crewai/resources/whale.jpg')
|
421 |
-
|
422 |
-
with col2:
|
423 |
-
# Input for the user
|
424 |
-
input_topic = st.text_area("What Exciting Adventures Awaits Us", height=100, placeholder="Start Our Story...")
|
425 |
-
st.session_state['on_topic'] = input_topic
|
426 |
-
# Button to run the process
|
427 |
-
if st.button("Create a Story"):
|
428 |
-
# Run the crewai process
|
429 |
-
with st.spinner('Generating Content...'):
|
430 |
-
result = crewai_process(input_topic)
|
431 |
-
# Display the result
|
432 |
-
st.session_state['text_block'] = result
|
433 |
-
st.text_area("Output", value=result , height=300)
|
434 |
-
|
435 |
-
with col3:
|
436 |
-
st.image('crewai/resources/clarifai.png')
|
437 |
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
|
|
|
|
450 |
with st.spinner('Generating Content...'):
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
if audio_error:
|
463 |
-
st.error(audio_error)
|
464 |
-
else:
|
465 |
-
st.audio(audio, format='audio/wav')
|
466 |
|
467 |
-
# Tab 3: User Input and Results
|
468 |
-
elif st.session_state.current_tab == tabs[2]:
|
469 |
-
with tab3:
|
470 |
-
|
471 |
-
|
472 |
-
if 'image_paths' in st.session_state and st.session_state['image_paths']:
|
473 |
-
# Create a slider for image selection
|
474 |
-
|
475 |
-
col1, col2 = st.columns([2, 3])
|
476 |
-
|
477 |
-
|
478 |
-
with col2:
|
479 |
-
# Display the selected image
|
480 |
-
|
481 |
-
image_index = st.radio(
|
482 |
-
"Choose an image",
|
483 |
-
options=list(range(len(st.session_state['image_paths']))),
|
484 |
-
format_func=lambda x: f"Image {x + 1}"
|
485 |
-
)
|
486 |
|
487 |
-
|
488 |
-
st.image(st.session_state['image_paths'][image_index])
|
489 |
-
|
490 |
-
with col1:
|
491 |
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
|
|
|
|
|
|
|
|
497 |
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
name = concept.name
|
502 |
-
# Add unique names to the set
|
503 |
-
unique_names.add(name)
|
504 |
-
|
505 |
-
# Display unique names
|
506 |
-
|
507 |
-
if unique_names:
|
508 |
-
st.write(', '.join(unique_names))
|
509 |
else:
|
510 |
-
st.
|
511 |
-
|
512 |
-
st.divider()
|
513 |
-
st.subheader("Description of Our Image")
|
514 |
-
|
515 |
-
image_text_output = analyze_image(st.session_state['image_paths'][image_index])
|
516 |
-
|
517 |
-
st.write(image_text_output)
|
518 |
-
st.divider()
|
519 |
-
|
520 |
-
st.header("Create a Story About This Image")
|
521 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
522 |
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
530 |
|
|
|
411 |
tab1, tab2, tab3 = st.tabs(tabs)
|
412 |
|
413 |
# Tab 1: Introduction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
414 |
|
415 |
+
with tab1:
|
416 |
+
# Set up the Streamlit interface
|
417 |
+
col1, col2, col3 = st.columns([1, 4, 1])
|
418 |
+
|
419 |
+
with col1:
|
420 |
+
st.image('crewai/resources/whale.jpg')
|
421 |
+
|
422 |
+
with col2:
|
423 |
+
# Input for the user
|
424 |
+
input_topic = st.text_area("What Exciting Adventures Awaits Us", height=100, placeholder="Start Our Story...")
|
425 |
+
st.session_state['on_topic'] = input_topic
|
426 |
+
# Button to run the process
|
427 |
+
if st.button("Create a Story"):
|
428 |
+
# Run the crewai process
|
429 |
with st.spinner('Generating Content...'):
|
430 |
+
result = crewai_process(input_topic)
|
431 |
+
# Display the result
|
432 |
+
st.session_state['text_block'] = result
|
433 |
+
st.text_area("Output", value=result , height=300)
|
434 |
+
|
435 |
+
with col3:
|
436 |
+
st.image('crewai/resources/clarifai.png')
|
437 |
+
|
438 |
+
# Tab 2: Data Visualization
|
439 |
+
|
440 |
+
with tab2:
|
|
|
|
|
|
|
|
|
441 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
442 |
|
443 |
+
# Streamlit main page
|
|
|
|
|
|
|
444 |
|
445 |
+
if st.button("Generate Images and Audio"):
|
446 |
+
|
447 |
+
sentence_chunks = split_text_into_sentences_and_chunks(st.session_state.text_block , 8)
|
448 |
+
prompts = [' '.join(chunk) for chunk in sentence_chunks]
|
449 |
+
cols = st.columns(4)
|
450 |
+
with st.spinner('Generating Content...'):
|
451 |
+
for i, prompt in enumerate(prompts):
|
452 |
+
image_path, img_error = generate_image(prompt+st.session_state.on_topic )
|
453 |
+
audio, audio_error = generate_audio(prompt)
|
454 |
|
455 |
+
with cols[i % 4]:
|
456 |
+
if img_error:
|
457 |
+
st.error(img_error)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
458 |
else:
|
459 |
+
st.session_state['image_paths'].append(image_path)
|
460 |
+
st.image(image_path, prompt, use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
461 |
|
462 |
+
if audio_error:
|
463 |
+
st.error(audio_error)
|
464 |
+
else:
|
465 |
+
st.audio(audio, format='audio/wav')
|
466 |
+
|
467 |
+
# Tab 3: User Input and Results
|
468 |
+
|
469 |
+
with tab3:
|
470 |
+
|
471 |
+
|
472 |
+
if 'image_paths' in st.session_state and st.session_state['image_paths']:
|
473 |
+
# Create a slider for image selection
|
474 |
+
|
475 |
+
col1, col2 = st.columns([2, 3])
|
476 |
+
|
477 |
+
|
478 |
+
with col2:
|
479 |
+
# Display the selected image
|
480 |
+
|
481 |
+
image_index = st.radio(
|
482 |
+
"Choose an image",
|
483 |
+
options=list(range(len(st.session_state['image_paths']))),
|
484 |
+
format_func=lambda x: f"Image {x + 1}"
|
485 |
+
)
|
486 |
+
|
487 |
+
|
488 |
+
st.image(st.session_state['image_paths'][image_index])
|
489 |
+
|
490 |
+
with col1:
|
491 |
+
|
492 |
+
st.header("Image Details")
|
493 |
+
st.divider()
|
494 |
+
st.subheader("Image Components")
|
495 |
+
|
496 |
+
image_conepts = get_image_concepts(st.session_state['image_paths'][image_index])
|
497 |
+
|
498 |
+
unique_names = set()
|
499 |
+
for region in image_conepts:
|
500 |
+
for concept in region.data.concepts:
|
501 |
+
name = concept.name
|
502 |
+
# Add unique names to the set
|
503 |
+
unique_names.add(name)
|
504 |
|
505 |
+
# Display unique names
|
506 |
+
|
507 |
+
if unique_names:
|
508 |
+
st.write(', '.join(unique_names))
|
509 |
+
else:
|
510 |
+
st.write("No unique items detected.")
|
511 |
+
|
512 |
+
st.divider()
|
513 |
+
st.subheader("Description of Our Image")
|
514 |
+
|
515 |
+
image_text_output = analyze_image(st.session_state['image_paths'][image_index])
|
516 |
+
|
517 |
+
st.write(image_text_output)
|
518 |
+
st.divider()
|
519 |
+
|
520 |
+
st.header("Create a Story About This Image")
|
521 |
+
|
522 |
+
|
523 |
+
# Button for actions related to the selected image
|
524 |
+
if st.button("Create a New Story"):
|
525 |
+
st.session_state['text_block'] = image_text_output
|
526 |
+
crewai_process(st.session_state['text_block'])
|
527 |
+
switch_tab(tabs[0])
|
528 |
+
|
529 |
+
|
530 |
|