Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -783,55 +783,20 @@ def load_example_audio(example_name):
|
|
| 783 |
return None
|
| 784 |
|
| 785 |
# Function to generate a shareable link
|
| 786 |
-
|
|
|
|
| 787 |
try:
|
| 788 |
# Check if we're on Hugging Face Spaces
|
| 789 |
space_id = os.getenv('SPACE_ID')
|
| 790 |
|
| 791 |
-
# If we don't have results yet, just share the current app
|
| 792 |
-
if results is None:
|
| 793 |
-
if space_id:
|
| 794 |
-
space_url = f"https://huggingface.co/spaces/{space_id}"
|
| 795 |
-
return f"Your Space is already public! Share this URL: {space_url}"
|
| 796 |
-
else:
|
| 797 |
-
if hasattr(interface, 'share_url') and interface.share_url:
|
| 798 |
-
return "Share this URL to let others use the app: " + interface.share_url
|
| 799 |
-
else:
|
| 800 |
-
return "Share link is not available. Make sure to set share=True when launching."
|
| 801 |
-
|
| 802 |
-
# If we have results, create a shareable link with the data
|
| 803 |
-
# For simplicity, we'll just create a JSON representation of the results
|
| 804 |
-
# In a real implementation, you might want to store this data in a database
|
| 805 |
-
# and generate a unique ID for it
|
| 806 |
-
|
| 807 |
-
# Prepare data for sharing
|
| 808 |
-
share_data = {
|
| 809 |
-
"audio_input": audio_input if isinstance(audio_input, str) else "uploaded_audio",
|
| 810 |
-
"generate_audio": generate_audio,
|
| 811 |
-
"chunk_duration": chunk_duration,
|
| 812 |
-
"results": []
|
| 813 |
-
}
|
| 814 |
-
|
| 815 |
-
# Add result data (simplified for sharing)
|
| 816 |
-
for result in results:
|
| 817 |
-
share_data["results"].append({
|
| 818 |
-
"chunk_index": result.get("chunk_index", 0),
|
| 819 |
-
"emotion": result.get("emotion", ""),
|
| 820 |
-
"transcription": result.get("transcription", ""),
|
| 821 |
-
"sentiment": result.get("sentiment", "")
|
| 822 |
-
})
|
| 823 |
-
|
| 824 |
-
# Encode the data as a URL parameter
|
| 825 |
-
encoded_data = urllib.parse.quote(json.dumps(share_data))
|
| 826 |
-
|
| 827 |
if space_id:
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
return f"Share this data with others and have them visit https://huggingface.co/spaces/{space_id} to see similar results:\n\n{json.dumps(share_data, indent=2)}"
|
| 831 |
else:
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
|
|
|
| 835 |
|
| 836 |
except Exception as e:
|
| 837 |
return f"Error generating share link: {str(e)}"
|
|
@@ -840,6 +805,7 @@ def generate_share_link(audio_input=None, generate_audio=True, chunk_duration=10
|
|
| 840 |
|
| 841 |
|
| 842 |
|
|
|
|
| 843 |
# Create the Gradio interface with proper output handling
|
| 844 |
with gr.Blocks(title="Affective Virtual Environments - Chunked Processing") as interface:
|
| 845 |
gr.Markdown("# Affective Virtual Environments")
|
|
@@ -945,6 +911,7 @@ with gr.Blocks(title="Affective Virtual Environments - Chunked Processing") as i
|
|
| 945 |
# Set up the button clicks
|
| 946 |
|
| 947 |
# Update the process_btn click handler to include results in the output
|
|
|
|
| 948 |
process_btn.click(
|
| 949 |
fn=process_and_display,
|
| 950 |
inputs=[audio_input, generate_audio_checkbox, chunk_duration_input],
|
|
@@ -955,8 +922,12 @@ with gr.Blocks(title="Affective Virtual Environments - Chunked Processing") as i
|
|
| 955 |
container['image'],
|
| 956 |
container['image_360'],
|
| 957 |
container['music']
|
| 958 |
-
]] + [viewer_html_output, js_output
|
| 959 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 960 |
|
| 961 |
clear_btn.click(
|
| 962 |
fn=clear_all,
|
|
@@ -977,15 +948,12 @@ with gr.Blocks(title="Affective Virtual Environments - Chunked Processing") as i
|
|
| 977 |
outputs=[audio_input, example_selector]
|
| 978 |
)
|
| 979 |
|
| 980 |
-
#
|
| 981 |
share_btn.click(
|
| 982 |
fn=generate_share_link,
|
| 983 |
-
inputs=[audio_input, generate_audio_checkbox, chunk_duration_input
|
| 984 |
outputs=[share_output]
|
| 985 |
)
|
| 986 |
-
|
| 987 |
-
# Add a state component to store the results
|
| 988 |
-
results_state = gr.State()
|
| 989 |
|
| 990 |
|
| 991 |
# Check if we're running on Hugging Face Spaces
|
|
|
|
| 783 |
return None
|
| 784 |
|
| 785 |
# Function to generate a shareable link
|
| 786 |
+
|
| 787 |
+
def generate_share_link(audio_input=None, generate_audio=True, chunk_duration=10):
|
| 788 |
try:
|
| 789 |
# Check if we're on Hugging Face Spaces
|
| 790 |
space_id = os.getenv('SPACE_ID')
|
| 791 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 792 |
if space_id:
|
| 793 |
+
space_url = f"https://huggingface.co/spaces/{space_id}"
|
| 794 |
+
return f"Your Space is already public! Share this URL: {space_url}\n\nTo share specific results, ask others to process the same audio with the same settings."
|
|
|
|
| 795 |
else:
|
| 796 |
+
if hasattr(interface, 'share_url') and interface.share_url:
|
| 797 |
+
return "Share this URL to let others use the app: " + interface.share_url + "\n\nTo share specific results, ask others to process the same audio with the same settings."
|
| 798 |
+
else:
|
| 799 |
+
return "Share link is not available. Make sure to set share=True when launching."
|
| 800 |
|
| 801 |
except Exception as e:
|
| 802 |
return f"Error generating share link: {str(e)}"
|
|
|
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
+
|
| 809 |
# Create the Gradio interface with proper output handling
|
| 810 |
with gr.Blocks(title="Affective Virtual Environments - Chunked Processing") as interface:
|
| 811 |
gr.Markdown("# Affective Virtual Environments")
|
|
|
|
| 911 |
# Set up the button clicks
|
| 912 |
|
| 913 |
# Update the process_btn click handler to include results in the output
|
| 914 |
+
# Remove the results_state component and simplify the process_btn click handler
|
| 915 |
process_btn.click(
|
| 916 |
fn=process_and_display,
|
| 917 |
inputs=[audio_input, generate_audio_checkbox, chunk_duration_input],
|
|
|
|
| 922 |
container['image'],
|
| 923 |
container['image_360'],
|
| 924 |
container['music']
|
| 925 |
+
]] + [viewer_html_output, js_output]
|
| 926 |
)
|
| 927 |
+
|
| 928 |
+
|
| 929 |
+
|
| 930 |
+
# Remove the results_state component
|
| 931 |
|
| 932 |
clear_btn.click(
|
| 933 |
fn=clear_all,
|
|
|
|
| 948 |
outputs=[audio_input, example_selector]
|
| 949 |
)
|
| 950 |
|
| 951 |
+
# Update the share button to not expect results
|
| 952 |
share_btn.click(
|
| 953 |
fn=generate_share_link,
|
| 954 |
+
inputs=[audio_input, generate_audio_checkbox, chunk_duration_input],
|
| 955 |
outputs=[share_output]
|
| 956 |
)
|
|
|
|
|
|
|
|
|
|
| 957 |
|
| 958 |
|
| 959 |
# Check if we're running on Hugging Face Spaces
|