ACloudCenter commited on
Commit
b15cc82
·
1 Parent(s): 468e8b7

Modify structure

Browse files
app.py ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import modal
4
+ import traceback
5
+
6
+ # --- Configuration ---
7
+ # This is the name of your Modal stub.
8
+ MODAL_STUB_NAME = "vibevoice-generator"
9
+ # This is the name of the remote class and method to call.
10
+ MODAL_FUNCTION_NAME = "VibeVoiceModel.generate_podcast"
11
+
12
+ # These lists are now hardcoded because the data lives on the Modal container.
13
+ # For a more dynamic app, you could create a small Modal function to fetch these lists.
14
+ AVAILABLE_MODELS = ["VibeVoice-1.5B", "VibeVoice-7B"]
15
+ AVAILABLE_VOICES = [
16
+ "en-Alice_woman_bgm", "en-Alice_woman", "en-Carter_man", "en-Frank_man",
17
+ "en-Maya_woman", "en-Yasser_man", "in-Samuel_man", "zh-Anchen_man_bgm",
18
+ "zh-Bowen_man", "zh-Xinran_woman"
19
+ ]
20
+ DEFAULT_SPEAKERS = ['en-Alice_woman', 'en-Carter_man', 'en-Frank_man', 'en-Maya_woman']
21
+
22
+ # --- Modal Connection ---
23
+ try:
24
+ # This looks up the remote function on Modal
25
+ # It will raise an error if the app isn't deployed (`modal deploy modal_runner.py`)
26
+ remote_generate_function = modal.Function.lookup(MODAL_STUB_NAME, MODAL_FUNCTION_NAME)
27
+ print("Successfully connected to Modal function.")
28
+ except modal.exception.NotFoundError:
29
+ print("ERROR: Modal function not found.")
30
+ print(f"Please deploy the Modal app first by running: modal deploy modal_runner.py")
31
+ remote_generate_function = None
32
+
33
+ # --- Gradio UI Definition ---
34
+ theme = gr.themes.Ocean(
35
+ primary_hue="indigo",
36
+ secondary_hue="fuchsia",
37
+ neutral_hue="slate",
38
+ ).set(
39
+ button_large_radius='*radius_sm'
40
+ )
41
+
42
+ def create_demo_interface():
43
+ with gr.Blocks(
44
+ title="VibeVoice - Conference Generator",
45
+ theme=theme,
46
+ ) as interface:
47
+ gr.HTML("""
48
+ <div style="width: 100%; margin-bottom: 20px;">
49
+ <img src="https://huggingface.co/spaces/ACloudCenter/Conference-Generator-VibeVoice/resolve/main/public/images/banner.png"
50
+ style="width: 100%; height: auto; border-radius: 15px; box-shadow: 0 10px 40px rgba(0,0,0,0.2);"
51
+ alt="VibeVoice Banner">
52
+ </div>
53
+ """)
54
+ gr.Markdown("## GPU processing is now offloaded to a Modal.com backend!")
55
+
56
+ with gr.Tabs():
57
+ with gr.Tab("Generate"):
58
+ gr.Markdown("### Generated Conference")
59
+ complete_audio_output = gr.Audio(
60
+ label="Complete Conference (Download)",
61
+ type="numpy",
62
+ autoplay=False,
63
+ show_download_button=True,
64
+ )
65
+
66
+ with gr.Row():
67
+ with gr.Column(scale=1):
68
+ gr.Markdown("### Conference Settings")
69
+ model_dropdown = gr.Dropdown(
70
+ choices=AVAILABLE_MODELS,
71
+ value=AVAILABLE_MODELS[0],
72
+ label="Model",
73
+ )
74
+ num_speakers = gr.Slider(
75
+ minimum=1, maximum=4, value=2, step=1,
76
+ label="Number of Speakers",
77
+ )
78
+
79
+ gr.Markdown("### Speaker Selection")
80
+ speaker_selections = []
81
+ for i in range(4):
82
+ speaker = gr.Dropdown(
83
+ choices=AVAILABLE_VOICES,
84
+ value=DEFAULT_SPEAKERS[i] if i < len(DEFAULT_SPEAKERS) else None,
85
+ label=f"Speaker {i+1}",
86
+ visible=(i < 2),
87
+ )
88
+ speaker_selections.append(speaker)
89
+
90
+ with gr.Accordion("Advanced Settings", open=False):
91
+ cfg_scale = gr.Slider(
92
+ minimum=1.0, maximum=2.0, value=1.3, step=0.05,
93
+ label="CFG Scale (Guidance Strength)",
94
+ )
95
+
96
+ with gr.Column(scale=2):
97
+ gr.Markdown("### Script Input")
98
+ script_input = gr.Textbox(
99
+ label="Conversation Script",
100
+ placeholder="Enter your conference script here...",
101
+ lines=12,
102
+ max_lines=20,
103
+ )
104
+ generate_btn = gr.Button(
105
+ "🚀 Generate Conference (on Modal)", size="lg",
106
+ variant="primary",
107
+ )
108
+ log_output = gr.Textbox(
109
+ label="Generation Log",
110
+ lines=8, max_lines=15,
111
+ interactive=False,
112
+ )
113
+
114
+ def update_speaker_visibility(num_speakers):
115
+ return [gr.update(visible=(i < num_speakers)) for i in range(4)]
116
+
117
+ num_speakers.change(
118
+ fn=update_speaker_visibility,
119
+ inputs=[num_speakers],
120
+ outputs=speaker_selections
121
+ )
122
+
123
+ def generate_podcast_wrapper(model_choice, num_speakers_val, script, *speakers_and_params):
124
+ if remote_generate_function is None:
125
+ return None, "ERROR: Modal function not deployed. Please contact the space owner."
126
+
127
+ # Show a message that we are calling the remote function
128
+ yield None, "🔄 Calling remote GPU on Modal.com... this may take a moment to start."
129
+
130
+ try:
131
+ speakers = speakers_and_params[:4]
132
+ cfg_scale_val = speakers_and_params[4]
133
+
134
+ # This is the call to the remote Modal function
135
+ result, log = remote_generate_function.remote(
136
+ num_speakers=int(num_speakers_val),
137
+ script=script,
138
+ speaker_1=speakers[0],
139
+ speaker_2=speakers[1],
140
+ speaker_3=speakers[2],
141
+ speaker_4=speakers[3],
142
+ cfg_scale=cfg_scale_val,
143
+ model_name=model_choice
144
+ )
145
+ yield result, log
146
+ except Exception as e:
147
+ tb = traceback.format_exc()
148
+ print(f"Error calling Modal: {e}")
149
+ yield None, f"An error occurred in the Gradio wrapper: {e}\n\n{tb}"
150
+
151
+ generate_btn.click(
152
+ fn=generate_podcast_wrapper,
153
+ inputs=[model_dropdown, num_speakers, script_input] + speaker_selections + [cfg_scale],
154
+ outputs=[complete_audio_output, log_output]
155
+ )
156
+ return interface
157
+
158
+ # --- Main Execution ---
159
+ if __name__ == "__main__":
160
+ if remote_generate_function is None:
161
+ # If Modal isn't set up, we can't launch the full app.
162
+ # We'll show a simplified UI with an error message.
163
+ with gr.Blocks(theme=theme) as interface:
164
+ gr.Markdown("# ❌ Configuration Error")
165
+ gr.Markdown(
166
+ "The Gradio application cannot connect to the Modal backend. "
167
+ "The Modal app has not been deployed yet. "
168
+ "Please run `modal deploy modal_runner.py` in your terminal and then refresh this page."
169
+ )
170
+ interface.launch()
171
+ else:
172
+ # Launch the full Gradio interface
173
+ interface = create_demo_interface()
174
+ interface.queue().launch(show_error=True)
public/images/banner.png ADDED

Git LFS Details

  • SHA256: 6e832e6a47bb49d144ce6ba21d2eb14ecf0a28604578f3094e492784ab250d0a
  • Pointer size: 131 Bytes
  • Size of remote file: 676 kB
public/images/chart.png ADDED

Git LFS Details

  • SHA256: 64464f28380f81e76c88d76431a08b48c7f82a283e17f2e32c241c4b03407d19
  • Pointer size: 131 Bytes
  • Size of remote file: 154 kB
public/images/diagram.jpg ADDED

Git LFS Details

  • SHA256: 353803ce2be393700ff3dfedd0a522b88ebd294702d0d2f51b6f7b7fe65d344f
  • Pointer size: 131 Bytes
  • Size of remote file: 342 kB
public/voices/Cherry.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0ac5796a412b2a4e191ecc037be6467cfd3c6233cf7dd2ce07d7742eb046cfbe
3
+ size 509537
public/voices/Chicago.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6be99cc80c226a150402e0ec92ac40206de08ff7399136fc309597b0bd8837ad
3
+ size 696782
public/voices/Janus.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4b8d608ec67b43a088e96691c009a095e488523a6aca29e1fa30d628e46e3ce7
3
+ size 528763
public/voices/Mantis.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e37695776f1c93c4c86c7ba1b26ea365af566363432a02cbd65ca571f99e3c14
3
+ size 619460
public/voices/Sponge.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c7ab366e71ec9c709d49cdb2778bf76f2de27cbbabb1d5452675b2b9a6c24d01
3
+ size 535450
public/voices/Starchild.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e4255d53586fae89e44ba64f13857cc72c823acfa013c47617b42425bfe96d1f
3
+ size 624894
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ modal