Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -745,8 +745,7 @@ with gr.Blocks(title="Affective Virtual Environments - Chunked Processing") as i
|
|
| 745 |
with gr.Row():
|
| 746 |
process_btn = gr.Button("Process Audio", variant="primary")
|
| 747 |
clear_btn = gr.Button("Clear All", variant="secondary")
|
| 748 |
-
open_viewer_btn = gr.Button("Open 360 Viewer in New Tab", variant="secondary")
|
| 749 |
-
|
| 750 |
|
| 751 |
# Add a loading indicator
|
| 752 |
loading_indicator = gr.HTML("""
|
|
@@ -771,47 +770,22 @@ with gr.Blocks(title="Affective Virtual Environments - Chunked Processing") as i
|
|
| 771 |
sentiment_output = gr.Label(label="Sentiment Analysis")
|
| 772 |
with gr.Row():
|
| 773 |
image_output = gr.Image(label="Generated Equirectangular Image")
|
| 774 |
-
image_360_output = gr.File(label="Download 360 Image", type="filepath")
|
| 775 |
with gr.Row():
|
| 776 |
audio_output = gr.Audio(label="Generated Music")
|
| 777 |
gr.HTML("<hr style='margin: 20px 0; border: 1px solid #ccc;'>")
|
| 778 |
|
| 779 |
-
group_components.append(chunk_group)
|
| 780 |
output_containers.append({
|
| 781 |
'emotion': emotion_output,
|
| 782 |
'transcription': transcription_output,
|
| 783 |
'sentiment': sentiment_output,
|
| 784 |
'image': image_output,
|
| 785 |
-
'image_360': image_360_output,
|
| 786 |
'music': audio_output
|
| 787 |
})
|
| 788 |
|
| 789 |
-
# Add components to display the fade animation
|
| 790 |
-
with gr.Row():
|
| 791 |
-
fade_preview_output = gr.Image(
|
| 792 |
-
label="Fade Animation Preview",
|
| 793 |
-
interactive=False
|
| 794 |
-
)
|
| 795 |
-
fade_animation_output = gr.File(
|
| 796 |
-
label="Download Fade Animation",
|
| 797 |
-
type="binary",
|
| 798 |
-
interactive=False
|
| 799 |
-
)
|
| 800 |
-
# In your output_containers, add the image_360 output
|
| 801 |
-
with gr.Group(visible=False) as chunk_group:
|
| 802 |
-
gr.Markdown(f"### Chunk {i+1} Results")
|
| 803 |
-
with gr.Row():
|
| 804 |
-
emotion_output = gr.Label(label="Acoustic Emotion Prediction")
|
| 805 |
-
transcription_output = gr.Label(label="Transcribed Text")
|
| 806 |
-
sentiment_output = gr.Label(label="Sentiment Analysis")
|
| 807 |
-
with gr.Row():
|
| 808 |
-
image_output = gr.Image(label="Generated Equirectangular Image")
|
| 809 |
-
image_360_output = gr.File(label="Download 360 Image", type="filepath") # New component
|
| 810 |
-
with gr.Row():
|
| 811 |
-
audio_output = gr.Audio(label="Generated Music")
|
| 812 |
-
gr.HTML("<hr style='margin: 20px 0; border: 1px solid #ccc;'>")
|
| 813 |
-
|
| 814 |
-
# Add the 360 viewer component
|
| 815 |
with gr.Row():
|
| 816 |
fade_preview_output = gr.Image(
|
| 817 |
label="Fade Animation Preview",
|
|
@@ -822,29 +796,22 @@ with gr.Blocks(title="Affective Virtual Environments - Chunked Processing") as i
|
|
| 822 |
type="binary",
|
| 823 |
interactive=False
|
| 824 |
)
|
| 825 |
-
viewer_html_output = gr.File(
|
| 826 |
label="Download 360 Viewer",
|
| 827 |
type="filepath",
|
| 828 |
interactive=False
|
| 829 |
)
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
label="Download 360 Viewer",
|
| 842 |
-
type="filepath",
|
| 843 |
-
interactive=False
|
| 844 |
-
)
|
| 845 |
-
|
| 846 |
-
# Add a button to open the HTML viewer in a new tab
|
| 847 |
-
open_viewer_btn = gr.Button("Open 360 Viewer in New Tab", variant="secondary")
|
| 848 |
|
| 849 |
# Function to open the HTML viewer in a new tab
|
| 850 |
def open_viewer_in_new_tab(viewer_html_path):
|
|
@@ -862,25 +829,6 @@ with gr.Blocks(title="Affective Virtual Environments - Chunked Processing") as i
|
|
| 862 |
return tmp_file.name
|
| 863 |
return None
|
| 864 |
|
| 865 |
-
# Set up the button click for opening the viewer
|
| 866 |
-
open_viewer_btn.click(
|
| 867 |
-
fn=open_viewer_in_new_tab,
|
| 868 |
-
inputs=[viewer_html_output],
|
| 869 |
-
outputs=[viewer_html_output] # This will update the file download link
|
| 870 |
-
)
|
| 871 |
-
|
| 872 |
-
# Function to handle example selection
|
| 873 |
-
def load_example(example_name):
|
| 874 |
-
if not example_name:
|
| 875 |
-
return None, None # Return None for both audio and example selector
|
| 876 |
-
|
| 877 |
-
# Get the path to the example audio file
|
| 878 |
-
example_path = load_example_audio(example_name)
|
| 879 |
-
|
| 880 |
-
# Return the example path to update the audio component
|
| 881 |
-
# The waveform will be automatically displayed by Gradio's Audio component
|
| 882 |
-
return example_path, example_name
|
| 883 |
-
|
| 884 |
# Function to clear audio input and all outputs
|
| 885 |
def clear_all():
|
| 886 |
# Create a list with None for all outputs
|
|
@@ -890,7 +838,7 @@ with gr.Blocks(title="Affective Virtual Environments - Chunked Processing") as i
|
|
| 890 |
outputs.extend([gr.Group(visible=False)] * len(group_components))
|
| 891 |
|
| 892 |
# For all output containers (set to None)
|
| 893 |
-
outputs.extend([None] * (len(output_containers) *
|
| 894 |
|
| 895 |
# For loading indicator (empty HTML)
|
| 896 |
outputs.append(gr.HTML(""))
|
|
@@ -901,13 +849,14 @@ with gr.Blocks(title="Affective Virtual Environments - Chunked Processing") as i
|
|
| 901 |
# For example selector (reset to None)
|
| 902 |
outputs.append(None)
|
| 903 |
|
| 904 |
-
# For fade preview and
|
|
|
|
| 905 |
outputs.append(None)
|
| 906 |
outputs.append(None)
|
| 907 |
|
| 908 |
return outputs
|
| 909 |
|
| 910 |
-
# Set up the button
|
| 911 |
process_btn.click(
|
| 912 |
fn=process_and_display,
|
| 913 |
inputs=[audio_input, generate_audio_checkbox, chunk_duration_input],
|
|
@@ -916,12 +865,11 @@ with gr.Blocks(title="Affective Virtual Environments - Chunked Processing") as i
|
|
| 916 |
container['transcription'],
|
| 917 |
container['sentiment'],
|
| 918 |
container['image'],
|
| 919 |
-
container['image_360'],
|
| 920 |
container['music']
|
| 921 |
-
]] + [fade_preview_output, fade_animation_output, viewer_html_output]
|
| 922 |
)
|
| 923 |
|
| 924 |
-
# Set up the clear button
|
| 925 |
clear_btn.click(
|
| 926 |
fn=clear_all,
|
| 927 |
inputs=[],
|
|
@@ -930,16 +878,21 @@ with gr.Blocks(title="Affective Virtual Environments - Chunked Processing") as i
|
|
| 930 |
container['transcription'],
|
| 931 |
container['sentiment'],
|
| 932 |
container['image'],
|
| 933 |
-
container['image_360'],
|
| 934 |
container['music']
|
| 935 |
-
]] + [loading_indicator
|
| 936 |
)
|
| 937 |
|
| 938 |
-
# Set up the example loading button
|
| 939 |
load_example_btn.click(
|
| 940 |
fn=load_example,
|
| 941 |
inputs=[example_selector],
|
| 942 |
outputs=[audio_input, example_selector]
|
| 943 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 944 |
|
| 945 |
interface.launch()
|
|
|
|
| 745 |
with gr.Row():
|
| 746 |
process_btn = gr.Button("Process Audio", variant="primary")
|
| 747 |
clear_btn = gr.Button("Clear All", variant="secondary")
|
| 748 |
+
open_viewer_btn = gr.Button("Open 360 Viewer in New Tab", variant="secondary")
|
|
|
|
| 749 |
|
| 750 |
# Add a loading indicator
|
| 751 |
loading_indicator = gr.HTML("""
|
|
|
|
| 770 |
sentiment_output = gr.Label(label="Sentiment Analysis")
|
| 771 |
with gr.Row():
|
| 772 |
image_output = gr.Image(label="Generated Equirectangular Image")
|
| 773 |
+
image_360_output = gr.File(label="Download 360 Image", type="filepath")
|
| 774 |
with gr.Row():
|
| 775 |
audio_output = gr.Audio(label="Generated Music")
|
| 776 |
gr.HTML("<hr style='margin: 20px 0; border: 1px solid #ccc;'>")
|
| 777 |
|
| 778 |
+
group_components.append(chunk_group)
|
| 779 |
output_containers.append({
|
| 780 |
'emotion': emotion_output,
|
| 781 |
'transcription': transcription_output,
|
| 782 |
'sentiment': sentiment_output,
|
| 783 |
'image': image_output,
|
| 784 |
+
'image_360': image_360_output,
|
| 785 |
'music': audio_output
|
| 786 |
})
|
| 787 |
|
| 788 |
+
# Add components to display the fade animation and 360 viewer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 789 |
with gr.Row():
|
| 790 |
fade_preview_output = gr.Image(
|
| 791 |
label="Fade Animation Preview",
|
|
|
|
| 796 |
type="binary",
|
| 797 |
interactive=False
|
| 798 |
)
|
| 799 |
+
viewer_html_output = gr.File(
|
| 800 |
label="Download 360 Viewer",
|
| 801 |
type="filepath",
|
| 802 |
interactive=False
|
| 803 |
)
|
| 804 |
+
|
| 805 |
+
# Function to handle example selection
|
| 806 |
+
def load_example(example_name):
|
| 807 |
+
if not example_name:
|
| 808 |
+
return None, None
|
| 809 |
+
|
| 810 |
+
# Get the path to the example audio file
|
| 811 |
+
example_path = load_example_audio(example_name)
|
| 812 |
+
|
| 813 |
+
# Return the example path to update the audio component
|
| 814 |
+
return example_path, example_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 815 |
|
| 816 |
# Function to open the HTML viewer in a new tab
|
| 817 |
def open_viewer_in_new_tab(viewer_html_path):
|
|
|
|
| 829 |
return tmp_file.name
|
| 830 |
return None
|
| 831 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 832 |
# Function to clear audio input and all outputs
|
| 833 |
def clear_all():
|
| 834 |
# Create a list with None for all outputs
|
|
|
|
| 838 |
outputs.extend([gr.Group(visible=False)] * len(group_components))
|
| 839 |
|
| 840 |
# For all output containers (set to None)
|
| 841 |
+
outputs.extend([None] * (len(output_containers) * 6))
|
| 842 |
|
| 843 |
# For loading indicator (empty HTML)
|
| 844 |
outputs.append(gr.HTML(""))
|
|
|
|
| 849 |
# For example selector (reset to None)
|
| 850 |
outputs.append(None)
|
| 851 |
|
| 852 |
+
# For fade preview, animation, and viewer (set to None)
|
| 853 |
+
outputs.append(None)
|
| 854 |
outputs.append(None)
|
| 855 |
outputs.append(None)
|
| 856 |
|
| 857 |
return outputs
|
| 858 |
|
| 859 |
+
# Set up the button clicks
|
| 860 |
process_btn.click(
|
| 861 |
fn=process_and_display,
|
| 862 |
inputs=[audio_input, generate_audio_checkbox, chunk_duration_input],
|
|
|
|
| 865 |
container['transcription'],
|
| 866 |
container['sentiment'],
|
| 867 |
container['image'],
|
| 868 |
+
container['image_360'],
|
| 869 |
container['music']
|
| 870 |
+
]] + [fade_preview_output, fade_animation_output, viewer_html_output]
|
| 871 |
)
|
| 872 |
|
|
|
|
| 873 |
clear_btn.click(
|
| 874 |
fn=clear_all,
|
| 875 |
inputs=[],
|
|
|
|
| 878 |
container['transcription'],
|
| 879 |
container['sentiment'],
|
| 880 |
container['image'],
|
| 881 |
+
container['image_360'],
|
| 882 |
container['music']
|
| 883 |
+
]] + [loading_indicator, chunk_duration_input, example_selector, fade_preview_output, fade_animation_output, viewer_html_output]
|
| 884 |
)
|
| 885 |
|
|
|
|
| 886 |
load_example_btn.click(
|
| 887 |
fn=load_example,
|
| 888 |
inputs=[example_selector],
|
| 889 |
outputs=[audio_input, example_selector]
|
| 890 |
)
|
| 891 |
+
|
| 892 |
+
open_viewer_btn.click(
|
| 893 |
+
fn=open_viewer_in_new_tab,
|
| 894 |
+
inputs=[viewer_html_output],
|
| 895 |
+
outputs=[viewer_html_output]
|
| 896 |
+
)
|
| 897 |
|
| 898 |
interface.launch()
|