Spaces:
Sleeping
Sleeping
Commit
·
c008cce
1
Parent(s):
e6e2817
update ui to correct file paths
Browse files
src/ui.py
CHANGED
|
@@ -5,30 +5,40 @@ from .agent import AudioAgent
|
|
| 5 |
# Global agent instance
|
| 6 |
agent = AudioAgent()
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def user_input(user_message, audio_files, history):
|
| 9 |
"""
|
| 10 |
Handle user input with text and audio files
|
| 11 |
"""
|
| 12 |
if not user_message.strip() and not audio_files:
|
| 13 |
return "", [], history
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
# Process audio files into URLs/paths
|
| 16 |
-
audio_file_paths = []
|
| 17 |
if audio_files:
|
| 18 |
for audio_file in audio_files:
|
| 19 |
if hasattr(audio_file, 'name'):
|
| 20 |
-
|
| 21 |
else:
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
audio_list = "\n".join([f"Audio file: {path}" for path in audio_file_paths])
|
| 27 |
combined_message = f"{user_message}\n\n{audio_list}" if user_message.strip() else audio_list
|
| 28 |
else:
|
| 29 |
combined_message = user_message
|
| 30 |
|
| 31 |
-
# Add user message to history
|
| 32 |
history.append({"role": "user", "content": combined_message})
|
| 33 |
return "", [], history
|
| 34 |
|
|
@@ -81,10 +91,7 @@ def bot_response_sync(history):
|
|
| 81 |
finally:
|
| 82 |
loop.close()
|
| 83 |
|
| 84 |
-
def create_interface():
|
| 85 |
-
"""
|
| 86 |
-
Create and return the enhanced Gradio interface
|
| 87 |
-
"""
|
| 88 |
with gr.Blocks(
|
| 89 |
title="Audio Agent - Professional Audio Processing",
|
| 90 |
theme=gr.themes.Soft(),
|
|
@@ -97,14 +104,9 @@ def create_interface():
|
|
| 97 |
margin: 10px 0;
|
| 98 |
}
|
| 99 |
"""
|
| 100 |
-
) as
|
| 101 |
-
|
| 102 |
gr.Markdown("""
|
| 103 |
# 🎵 Audio Agent - Professional Audio Processing
|
| 104 |
-
|
| 105 |
-
Upload audio files and describe what you want to achieve. The agent will process your request
|
| 106 |
-
and provide clean, direct responses!
|
| 107 |
-
|
| 108 |
**Supported formats**: MP3, WAV, M4A, FLAC, AAC, OGG
|
| 109 |
""")
|
| 110 |
|
|
@@ -114,9 +116,7 @@ def create_interface():
|
|
| 114 |
type="messages",
|
| 115 |
height=400,
|
| 116 |
show_copy_button=True,
|
| 117 |
-
show_share_button=False
|
| 118 |
-
avatar_images=(None, "🎵"),
|
| 119 |
-
bubble_full_width=False
|
| 120 |
)
|
| 121 |
|
| 122 |
with gr.Column(scale=1):
|
|
@@ -226,12 +226,12 @@ def create_interface():
|
|
| 226 |
examples_section
|
| 227 |
)
|
| 228 |
|
| 229 |
-
return
|
| 230 |
|
| 231 |
if __name__ == "__main__":
|
| 232 |
demo = create_interface()
|
| 233 |
demo.launch(
|
| 234 |
-
share=
|
| 235 |
server_name="0.0.0.0",
|
| 236 |
server_port=7861,
|
| 237 |
show_error=True
|
|
|
|
| 5 |
# Global agent instance
|
| 6 |
agent = AudioAgent()
|
| 7 |
|
| 8 |
+
# Global demo instance
|
| 9 |
+
demo = None
|
| 10 |
+
|
| 11 |
+
def get_share_url(path):
|
| 12 |
+
"""Get the share URL for a given path"""
|
| 13 |
+
if not demo:
|
| 14 |
+
return path
|
| 15 |
+
return f"{demo.share_url}/gradio_api/file={path}"
|
| 16 |
+
|
| 17 |
def user_input(user_message, audio_files, history):
|
| 18 |
"""
|
| 19 |
Handle user input with text and audio files
|
| 20 |
"""
|
| 21 |
if not user_message.strip() and not audio_files:
|
| 22 |
return "", [], history
|
| 23 |
+
|
| 24 |
+
# Process audio files into URLs
|
| 25 |
+
audio_file_urls = []
|
| 26 |
|
|
|
|
|
|
|
| 27 |
if audio_files:
|
| 28 |
for audio_file in audio_files:
|
| 29 |
if hasattr(audio_file, 'name'):
|
| 30 |
+
file_path = audio_file.name
|
| 31 |
else:
|
| 32 |
+
file_path = str(audio_file)
|
| 33 |
+
|
| 34 |
+
audio_file_urls.append(get_share_url(file_path))
|
| 35 |
|
| 36 |
+
if audio_file_urls:
|
| 37 |
+
audio_list = "\n".join([f"Audio file: {url}" for url in audio_file_urls])
|
|
|
|
| 38 |
combined_message = f"{user_message}\n\n{audio_list}" if user_message.strip() else audio_list
|
| 39 |
else:
|
| 40 |
combined_message = user_message
|
| 41 |
|
|
|
|
| 42 |
history.append({"role": "user", "content": combined_message})
|
| 43 |
return "", [], history
|
| 44 |
|
|
|
|
| 91 |
finally:
|
| 92 |
loop.close()
|
| 93 |
|
| 94 |
+
def create_interface():
|
|
|
|
|
|
|
|
|
|
| 95 |
with gr.Blocks(
|
| 96 |
title="Audio Agent - Professional Audio Processing",
|
| 97 |
theme=gr.themes.Soft(),
|
|
|
|
| 104 |
margin: 10px 0;
|
| 105 |
}
|
| 106 |
"""
|
| 107 |
+
) as interface:
|
|
|
|
| 108 |
gr.Markdown("""
|
| 109 |
# 🎵 Audio Agent - Professional Audio Processing
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
**Supported formats**: MP3, WAV, M4A, FLAC, AAC, OGG
|
| 111 |
""")
|
| 112 |
|
|
|
|
| 116 |
type="messages",
|
| 117 |
height=400,
|
| 118 |
show_copy_button=True,
|
| 119 |
+
show_share_button=False
|
|
|
|
|
|
|
| 120 |
)
|
| 121 |
|
| 122 |
with gr.Column(scale=1):
|
|
|
|
| 226 |
examples_section
|
| 227 |
)
|
| 228 |
|
| 229 |
+
return interface
|
| 230 |
|
| 231 |
if __name__ == "__main__":
|
| 232 |
demo = create_interface()
|
| 233 |
demo.launch(
|
| 234 |
+
share=True,
|
| 235 |
server_name="0.0.0.0",
|
| 236 |
server_port=7861,
|
| 237 |
show_error=True
|