CuddleBuddys commited on
Commit
002c88f
1 Parent(s): e0566c0

Update openvoice_app.py

Browse files
Files changed (1) hide show
  1. openvoice_app.py +75 -66
openvoice_app.py CHANGED
@@ -84,8 +84,18 @@ def send_email_with_file(recipient_email, file_path, subject, body):
84
  print(f"An error occurred while sending email: {e}")
85
  return False
86
 
 
 
 
 
 
 
 
87
  # Predict function
88
- def predict(prompt, style, audio_file_pth, voice_name, customer_email):
 
 
 
89
  text_hint = 'Your file will only be saved for 24 hours.\n'
90
  if len(prompt) < 2:
91
  text_hint += "[ERROR] Please provide a longer prompt text.\n"
@@ -116,74 +126,73 @@ def predict(prompt, style, audio_file_pth, voice_name, customer_email):
116
 
117
  return text_hint, save_path, audio_file_pth
118
 
119
- # Consent agreement text
120
- CONSENT_TEXT = """
121
- By using this app, you agree to the following:
122
-
123
- 1. This app is intended for use only with CuddleBuddy products.
124
- 2. CuddleBuddy and any of its partners are not responsible for any misuse of this app or its output.
125
- 3. You will not use this app for any illegal or unethical purposes.
126
- 4. You understand that the voice cloning technology should be used responsibly and with respect for others' privacy and rights.
127
-
128
- Do you agree to these terms?
129
- """
130
-
131
- # Function to handle consent
132
- def handle_consent(agree):
133
- if agree:
134
- return gr.update(visible=True), gr.update(visible=False)
135
- else:
136
- return gr.update(visible=False), gr.update(visible=True)
137
-
138
  # Gradio interface setup
139
  with gr.Blocks(gr.themes.Glass()) as demo:
140
- consent_view = gr.Column(visible=True)
141
- main_view = gr.Column(visible=False)
142
-
143
- with consent_view:
144
- gr.Markdown("# Consent Agreement")
145
- gr.Markdown(CONSENT_TEXT)
146
- agree_button = gr.Button("I Agree")
147
- disagree_button = gr.Button("I Disagree")
 
 
 
 
 
 
 
 
148
 
149
- with main_view:
150
- with gr.Row():
151
- with gr.Column():
152
- input_text_gr = gr.Textbox(
153
- label="Create This",
154
- info="One or two sentences at a time is better. Up to 200 text characters.",
155
- value="He hoped there would be stew for dinner, turnips and carrots and bruised potatoes and fat mutton pieces to be ladled out in thick, peppered, flour-fattened sauce.",
156
- )
157
- style_gr = gr.Dropdown(
158
- label="Style",
159
- choices=['default', 'whispering', 'cheerful', 'terrified', 'angry', 'sad', 'friendly'],
160
- info="Please upload a reference audio file that is at least 1 minute long. For best results, ensure the audio is clear. You can use Adobe Podcast Enhance(https://podcast.adobe.com/enhance) to improve the audio quality before uploading.",
161
- max_choices=1,
162
- value="default",
163
- )
164
- ref_gr = gr.Audio(
165
- label="Original Audio",
166
- type="filepath",
167
- sources=["upload"],
168
- )
169
- voice_name_gr = gr.Textbox(
170
- label="Your name and Product you bought",
171
- value="Sam"
172
- )
173
- customer_email_gr = gr.Textbox(
174
- label="Your Email",
175
- info="We'll send you a downloadable file to this email address."
176
- )
177
- tts_button = gr.Button("Start", elem_id="send-btn", visible=True)
178
-
179
- with gr.Column():
180
- out_text_gr = gr.Text(label="Info")
181
- audio_gr = gr.Audio(label="Replicated Sound", autoplay=True)
182
- ref_audio_gr = gr.Audio(label="Original Audio Used ")
183
-
184
- agree_button.click(handle_consent, inputs=[gr.Boolean(True)], outputs=[main_view, consent_view])
185
- disagree_button.click(handle_consent, inputs=[gr.Boolean(False)], outputs=[main_view, consent_view])
186
- tts_button.click(predict, [input_text_gr, style_gr, ref_gr, voice_name_gr, customer_email_gr], outputs=[out_text_gr, audio_gr, ref_audio_gr])
 
 
 
 
 
 
 
 
 
 
187
 
188
  demo.queue()
189
  demo.launch(debug=True, show_api=False, share=args.share)
 
84
  print(f"An error occurred while sending email: {e}")
85
  return False
86
 
87
+ # New function to handle consent
88
+ def check_consent(agreement):
89
+ if agreement:
90
+ return gr.update(visible=True), gr.update(visible=False)
91
+ else:
92
+ return gr.update(visible=False), gr.update(visible=True)
93
+
94
  # Predict function
95
+ def predict(agreement, prompt, style, audio_file_pth, voice_name, customer_email):
96
+ if not agreement:
97
+ return "You must agree to the terms before using this application.", None, None
98
+
99
  text_hint = 'Your file will only be saved for 24 hours.\n'
100
  if len(prompt) < 2:
101
  text_hint += "[ERROR] Please provide a longer prompt text.\n"
 
126
 
127
  return text_hint, save_path, audio_file_pth
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  # Gradio interface setup
130
  with gr.Blocks(gr.themes.Glass()) as demo:
131
+ # Consent view
132
+ with gr.Row(visible=True) as consent_row:
133
+ consent_text = gr.Markdown(
134
+ """
135
+ # Consent Agreement
136
+
137
+ By using this application, you agree to the following terms:
138
+
139
+ 1. This app will only be used for CuddleBuddy products.
140
+ 2. CuddleBuddy and any of its partners are not responsible for any misuse of this application.
141
+ 3. You understand that the voice cloning technology should be used responsibly and ethically.
142
+
143
+ Do you agree to these terms?
144
+ """
145
+ )
146
+ consent_checkbox = gr.Checkbox(label="I agree to the terms")
147
 
148
+ # Main application view
149
+ with gr.Row(visible=False) as main_app:
150
+ with gr.Column():
151
+ input_text_gr = gr.Textbox(
152
+ label="Create This",
153
+ info="One or two sentences at a time is better. Up to 200 text characters.",
154
+ value="He hoped there would be stew for dinner, turnips and carrots and bruised potatoes and fat mutton pieces to be ladled out in thick, peppered, flour-fattened sauce.",
155
+ )
156
+ style_gr = gr.Dropdown(
157
+ label="Style",
158
+ choices=['default', 'whispering', 'cheerful', 'terrified', 'angry', 'sad', 'friendly'],
159
+ info="Please upload a reference audio file that is at least 1 minute long. For best results, ensure the audio is clear. You can use Adobe Podcast Enhance(https://podcast.adobe.com/enhance) to improve the audio quality before uploading.",
160
+ max_choices=1,
161
+ value="default",
162
+ )
163
+ ref_gr = gr.Audio(
164
+ label="Original Audio",
165
+ type="filepath",
166
+ sources=["upload"],
167
+ )
168
+ voice_name_gr = gr.Textbox(
169
+ label="Your name and Product you bought",
170
+ value="Sam"
171
+ )
172
+ customer_email_gr = gr.Textbox(
173
+ label="Your Email",
174
+ info="We'll send you a downloadable file to this email address."
175
+ )
176
+ tts_button = gr.Button("Start", elem_id="send-btn", visible=True)
177
+
178
+ with gr.Column():
179
+ out_text_gr = gr.Text(label="Info")
180
+ audio_gr = gr.Audio(label="Replicated Sound", autoplay=True)
181
+ ref_audio_gr = gr.Audio(label="Original Audio Used ")
182
+
183
+ # Connect the consent checkbox to show/hide views
184
+ consent_checkbox.change(
185
+ check_consent,
186
+ inputs=[consent_checkbox],
187
+ outputs=[main_app, consent_row]
188
+ )
189
+
190
+ # Modify the click event to include the consent check
191
+ tts_button.click(
192
+ predict,
193
+ inputs=[consent_checkbox, input_text_gr, style_gr, ref_gr, voice_name_gr, customer_email_gr],
194
+ outputs=[out_text_gr, audio_gr, ref_audio_gr]
195
+ )
196
 
197
  demo.queue()
198
  demo.launch(debug=True, show_api=False, share=args.share)