eaglelandsonce commited on
Commit
cec3e64
·
verified ·
1 Parent(s): 16feab9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +116 -103
app.py CHANGED
@@ -397,121 +397,134 @@ st.set_page_config(layout="wide")
397
  st.markdown("<h1 style='text-align: center;'>Clarifai Story Teller</h1>", unsafe_allow_html=True)
398
  st.markdown("<h2 style='text-align: center;'>Branching Reading Adventure</h2>", unsafe_allow_html=True)
399
 
 
 
 
 
 
 
 
 
 
400
 
401
  # Create tabs
402
- tab1, tab2, tab3 = st.tabs(["Create Your Story Script", "Build Your Image-Audio Book", "Interact with Your Characters"])
403
 
404
  # Tab 1: Introduction
405
- with tab1:
406
- # Set up the Streamlit interface
407
- col1, col2, col3 = st.columns([1, 4, 1])
408
-
409
- with col1:
410
- st.image('crewai/resources/whale.jpg')
411
-
412
- with col2:
413
- # Input for the user
414
- input_topic = st.text_area("What Exciting Adventures Awaits Us", height=100, placeholder="Start Our Story...")
415
- st.session_state['on_topic'] = input_topic
416
- # Button to run the process
417
- if st.button("Create a Story"):
418
- # Run the crewai process
419
- with st.spinner('Generating Content...'):
420
- result = crewai_process(input_topic)
421
- # Display the result
422
- st.session_state['text_block'] = result
423
- st.text_area("Output", value=result , height=300)
424
-
425
- with col3:
426
- st.image('crewai/resources/clarifai.png')
 
427
 
428
  # Tab 2: Data Visualization
429
- with tab2:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
430
 
 
 
 
431
 
432
- # Streamlit main page
433
 
434
- if st.button("Generate Images and Audio"):
435
-
436
- sentence_chunks = split_text_into_sentences_and_chunks(st.session_state.text_block , 8)
437
- prompts = [' '.join(chunk) for chunk in sentence_chunks]
438
- cols = st.columns(4)
439
- with st.spinner('Generating Content...'):
440
- for i, prompt in enumerate(prompts):
441
- image_path, img_error = generate_image(prompt+st.session_state.on_topic )
442
- audio, audio_error = generate_audio(prompt)
443
 
444
- with cols[i % 4]:
445
- if img_error:
446
- st.error(img_error)
447
- else:
448
- st.session_state['image_paths'].append(image_path)
449
- st.image(image_path, prompt, use_column_width=True)
450
 
451
- if audio_error:
452
- st.error(audio_error)
453
- else:
454
- st.audio(audio, format='audio/wav')
455
-
456
- # Tab 3: User Input and Results
457
- with tab3:
458
-
459
-
460
- if 'image_paths' in st.session_state and st.session_state['image_paths']:
461
- # Create a slider for image selection
462
-
463
- col1, col2 = st.columns([2, 3])
464
-
465
-
466
- with col2:
467
- # Display the selected image
468
-
469
- image_index = st.radio(
470
- "Choose an image",
471
- options=list(range(len(st.session_state['image_paths']))),
472
- format_func=lambda x: f"Image {x + 1}"
473
- )
474
-
475
-
476
- st.image(st.session_state['image_paths'][image_index])
477
-
478
- with col1:
479
-
480
- st.header("Image Details")
481
- st.divider()
482
- st.subheader("Image Components")
483
 
484
- image_conepts = get_image_concepts(st.session_state['image_paths'][image_index])
485
-
486
- unique_names = set()
487
- for region in image_conepts:
488
- for concept in region.data.concepts:
489
- name = concept.name
490
- # Add unique names to the set
491
- unique_names.add(name)
 
492
 
493
- # Display unique names
494
-
495
- if unique_names:
496
- st.write(', '.join(unique_names))
497
- else:
498
- st.write("No unique items detected.")
499
-
500
- st.divider()
501
- st.subheader("Description of Our Image")
502
-
503
- image_text_output = analyze_image(st.session_state['image_paths'][image_index])
504
-
505
- st.write(image_text_output)
506
- st.divider()
507
-
508
- st.header("Create a Story About This Image")
509
-
510
-
511
- # Button for actions related to the selected image
512
- if st.button("Create a New Story"):
513
- st.session_state['text_block'] = image_text_output
514
- #crewai_process(st.session_state['text_block'])
515
- #switch_tab(1)
516
 
517
 
 
397
  st.markdown("<h1 style='text-align: center;'>Clarifai Story Teller</h1>", unsafe_allow_html=True)
398
  st.markdown("<h2 style='text-align: center;'>Branching Reading Adventure</h2>", unsafe_allow_html=True)
399
 
400
+ tabs = ["Create Your Story Script", "Build Your Image-Audio Book", "Interact with Your Characters"]
401
+
402
+ # Initialize the current tab in session state
403
+ if "current_tab" not in st.session_state:
404
+ st.session_state.current_tab = tabs[0]
405
+
406
+ # Function to switch tabs
407
+ def switch_tab(tab_name):
408
+ st.session_state.current_tab = tab_name
409
 
410
  # Create tabs
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
  # Tab 2: Data Visualization
439
+ elif st.session_state.current_tab == tabs[1]:
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
+ 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
+ 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