Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from gradio_client import Client
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
def create_dubsync_interface():
|
| 5 |
"""Create a wrapper interface for the DubSync space using gradio_client"""
|
| 6 |
-
|
| 7 |
try:
|
| 8 |
# Connect to your private space
|
| 9 |
-
client = Client("Tamiloneto8/Test1", hf_token=
|
| 10 |
-
|
| 11 |
def process_audio_wrapper(audio_file, target_language):
|
| 12 |
"""Wrapper function to interact with the private space"""
|
| 13 |
if not audio_file or not target_language:
|
| 14 |
return "Please provide both audio file and target language", None
|
| 15 |
-
|
| 16 |
try:
|
| 17 |
# Call the main processing function from your space
|
| 18 |
result = client.predict(
|
|
@@ -20,19 +24,18 @@ def create_dubsync_interface():
|
|
| 20 |
target_lang=target_language,
|
| 21 |
api_name="/process_audio_pipeline_step1" # This should match your space's API endpoint
|
| 22 |
)
|
| 23 |
-
|
| 24 |
# Extract the relevant outputs from the result
|
| 25 |
-
# Based on your code, the function returns multiple outputs
|
| 26 |
if isinstance(result, (list, tuple)) and len(result) > 1:
|
| 27 |
-
status_text = result[0]
|
| 28 |
-
output_audio = result[-1] if len(result) > 10 else None
|
| 29 |
return status_text, output_audio
|
| 30 |
else:
|
| 31 |
return str(result), None
|
| 32 |
-
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error processing audio: {str(e)}", None
|
| 35 |
-
|
| 36 |
# Create a simplified interface
|
| 37 |
interface = gr.Interface(
|
| 38 |
fn=process_audio_wrapper,
|
|
@@ -50,15 +53,11 @@ def create_dubsync_interface():
|
|
| 50 |
],
|
| 51 |
title="🎬 DubSync - AI Audio Dubbing",
|
| 52 |
description="Transform your audio into another Indian language with AI dubbing technology.",
|
| 53 |
-
theme=gr.themes.Soft()
|
| 54 |
-
examples=[
|
| 55 |
-
["sample_audio.wav", "Hindi"],
|
| 56 |
-
["sample_audio.wav", "Tamil"]
|
| 57 |
-
]
|
| 58 |
)
|
| 59 |
-
|
| 60 |
return interface
|
| 61 |
-
|
| 62 |
except Exception as e:
|
| 63 |
print(f"Error connecting to private space: {e}")
|
| 64 |
return None
|
|
@@ -67,7 +66,7 @@ def create_dubsync_interface():
|
|
| 67 |
if __name__ == "__main__":
|
| 68 |
# First, install gradio_client: pip install gradio_client
|
| 69 |
interface = create_dubsync_interface()
|
| 70 |
-
|
| 71 |
if interface:
|
| 72 |
interface.launch(
|
| 73 |
show_error=True,
|
|
@@ -76,4 +75,4 @@ if __name__ == "__main__":
|
|
| 76 |
server_port=7860
|
| 77 |
)
|
| 78 |
else:
|
| 79 |
-
print("Failed to create interface")
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
from gradio_client import Client
|
| 4 |
|
| 5 |
+
# Environment variables
|
| 6 |
+
token = os.getenv("HUGGINGFACE_TOKEN")
|
| 7 |
+
|
| 8 |
def create_dubsync_interface():
|
| 9 |
"""Create a wrapper interface for the DubSync space using gradio_client"""
|
| 10 |
+
|
| 11 |
try:
|
| 12 |
# Connect to your private space
|
| 13 |
+
client = Client("Tamiloneto8/Test1", hf_token=token, repo_type="space")
|
| 14 |
+
|
| 15 |
def process_audio_wrapper(audio_file, target_language):
|
| 16 |
"""Wrapper function to interact with the private space"""
|
| 17 |
if not audio_file or not target_language:
|
| 18 |
return "Please provide both audio file and target language", None
|
| 19 |
+
|
| 20 |
try:
|
| 21 |
# Call the main processing function from your space
|
| 22 |
result = client.predict(
|
|
|
|
| 24 |
target_lang=target_language,
|
| 25 |
api_name="/process_audio_pipeline_step1" # This should match your space's API endpoint
|
| 26 |
)
|
| 27 |
+
|
| 28 |
# Extract the relevant outputs from the result
|
|
|
|
| 29 |
if isinstance(result, (list, tuple)) and len(result) > 1:
|
| 30 |
+
status_text = result[0]
|
| 31 |
+
output_audio = result[-1] if len(result) > 10 else None
|
| 32 |
return status_text, output_audio
|
| 33 |
else:
|
| 34 |
return str(result), None
|
| 35 |
+
|
| 36 |
except Exception as e:
|
| 37 |
return f"Error processing audio: {str(e)}", None
|
| 38 |
+
|
| 39 |
# Create a simplified interface
|
| 40 |
interface = gr.Interface(
|
| 41 |
fn=process_audio_wrapper,
|
|
|
|
| 53 |
],
|
| 54 |
title="🎬 DubSync - AI Audio Dubbing",
|
| 55 |
description="Transform your audio into another Indian language with AI dubbing technology.",
|
| 56 |
+
theme=gr.themes.Soft()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
+
|
| 59 |
return interface
|
| 60 |
+
|
| 61 |
except Exception as e:
|
| 62 |
print(f"Error connecting to private space: {e}")
|
| 63 |
return None
|
|
|
|
| 66 |
if __name__ == "__main__":
|
| 67 |
# First, install gradio_client: pip install gradio_client
|
| 68 |
interface = create_dubsync_interface()
|
| 69 |
+
|
| 70 |
if interface:
|
| 71 |
interface.launch(
|
| 72 |
show_error=True,
|
|
|
|
| 75 |
server_port=7860
|
| 76 |
)
|
| 77 |
else:
|
| 78 |
+
print("Failed to create interface")
|