Update app.py
Browse files
app.py
CHANGED
|
@@ -2,27 +2,28 @@ from pydub import AudioSegment
|
|
| 2 |
from io import BytesIO
|
| 3 |
import gradio as gr
|
| 4 |
import binascii
|
| 5 |
-
|
| 6 |
|
| 7 |
def handler(input_text):
|
| 8 |
hex_data = input_text
|
| 9 |
audio_bytes = binascii.unhexlify(hex_data)
|
| 10 |
audio_segment = AudioSegment.from_file(BytesIO(audio_bytes), format="mp3")
|
| 11 |
-
|
|
|
|
| 12 |
output_buffer = BytesIO()
|
| 13 |
audio_segment.export(output_buffer, format="mp3")
|
| 14 |
-
|
| 15 |
return output_buffer
|
| 16 |
|
| 17 |
-
|
| 18 |
-
# 创建 Gradio 界面
|
| 19 |
def create_interface():
|
| 20 |
with gr.Blocks() as demo:
|
| 21 |
with gr.Row():
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
|
|
|
| 26 |
submit_btn.click(
|
| 27 |
fn=handler,
|
| 28 |
inputs=[input_text],
|
|
@@ -33,4 +34,5 @@ def create_interface():
|
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
demo = create_interface()
|
|
|
|
| 36 |
demo.launch()
|
|
|
|
| 2 |
from io import BytesIO
|
| 3 |
import gradio as gr
|
| 4 |
import binascii
|
|
|
|
| 5 |
|
| 6 |
def handler(input_text):
|
| 7 |
hex_data = input_text
|
| 8 |
audio_bytes = binascii.unhexlify(hex_data)
|
| 9 |
audio_segment = AudioSegment.from_file(BytesIO(audio_bytes), format="mp3")
|
| 10 |
+
|
| 11 |
+
# 创建内存缓冲区并导出MP3
|
| 12 |
output_buffer = BytesIO()
|
| 13 |
audio_segment.export(output_buffer, format="mp3")
|
| 14 |
+
|
| 15 |
return output_buffer
|
| 16 |
|
|
|
|
|
|
|
| 17 |
def create_interface():
|
| 18 |
with gr.Blocks() as demo:
|
| 19 |
with gr.Row():
|
| 20 |
+
# 创建多行文本输入框用于HEX代码
|
| 21 |
+
input_text = gr.Textbox(label="Input MP3 Hex Code", lines=10)
|
| 22 |
+
# 创建音频输出组件
|
| 23 |
+
output_audio = gr.Audio(label="Output Audio")
|
| 24 |
|
| 25 |
+
# 添加提交按钮
|
| 26 |
+
submit_btn = gr.Button("Convert to MP3")
|
| 27 |
submit_btn.click(
|
| 28 |
fn=handler,
|
| 29 |
inputs=[input_text],
|
|
|
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|
| 36 |
demo = create_interface()
|
| 37 |
+
# 启动Gradio界面
|
| 38 |
demo.launch()
|