CuddleBuddys commited on
Commit
7b25572
1 Parent(s): afcdb6c

Update openvoice_app.py

Browse files
Files changed (1) hide show
  1. openvoice_app.py +52 -44
openvoice_app.py CHANGED
@@ -7,6 +7,8 @@ from dotenv import load_dotenv
7
  from elevenlabs.client import ElevenLabs
8
  from elevenlabs import play, save
9
  import base64
 
 
10
 
11
  # Load environment variables
12
  load_dotenv()
@@ -84,18 +86,45 @@ 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
- # 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"
@@ -124,29 +153,16 @@ def predict(agreement, prompt, style, audio_file_pth, voice_name, customer_email
124
  else:
125
  text_hint += "Failed to send email with the voice file. Please try again later.\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",
@@ -166,9 +182,13 @@ with gr.Blocks(gr.themes.Glass()) as demo:
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."
@@ -180,19 +200,7 @@ with gr.Blocks(gr.themes.Glass()) as demo:
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)
@@ -202,4 +210,4 @@ footer {visibility: hidden}
202
  audio .btn-container {display: none}
203
  """
204
 
205
- demo.add_css(css)
 
7
  from elevenlabs.client import ElevenLabs
8
  from elevenlabs import play, save
9
  import base64
10
+ import psycopg2
11
+ from urllib.parse import urlparse, parse_qs
12
 
13
  # Load environment variables
14
  load_dotenv()
 
86
  print(f"An error occurred while sending email: {e}")
87
  return False
88
 
89
+ # Database connection details
90
+ connection_string = os.environ.get("DATABASE_URL")
91
+ result = urlparse(connection_string)
92
+ user = result.username
93
+ password = result.password
94
+ host = result.hostname
95
+ port = result.port
96
+ database = result.path[1:]
97
+ sslmode = parse_qs(result.query)['sslmode'][0]
98
+
99
+ # Function to add user information to the database
100
+ def add_user_info_to_db(email, order, sample_audio, name):
101
+ connection = psycopg2.connect(
102
+ dbname=database,
103
+ user=user,
104
+ password=password,
105
+ host=host,
106
+ port=port,
107
+ sslmode=sslmode
108
+ )
109
+ cursor = connection.cursor()
110
+
111
+ insert_query = """
112
+ INSERT INTO example_table (email, order, sample_audio, name)
113
+ VALUES (%s, %s, %s, %s);
114
+ """
115
+ try:
116
+ cursor.execute(insert_query, (email, order, sample_audio, name))
117
+ connection.commit()
118
+ print("User information added to the database successfully")
119
+ except Exception as error:
120
+ print(f"Error occurred during data insertion: {error}")
121
+ connection.rollback()
122
+ finally:
123
+ cursor.close()
124
+ connection.close()
125
 
126
  # Predict function
127
+ def predict(prompt, style, audio_file_pth, voice_name, customer_email, order):
 
 
 
128
  text_hint = 'Your file will only be saved for 24 hours.\n'
129
  if len(prompt) < 2:
130
  text_hint += "[ERROR] Please provide a longer prompt text.\n"
 
153
  else:
154
  text_hint += "Failed to send email with the voice file. Please try again later.\n"
155
 
156
+ # Add user information to the database
157
+ with open(audio_file_pth, "rb") as f:
158
+ sample_audio = f.read()
159
+ add_user_info_to_db(customer_email, order, sample_audio, voice_name)
160
+
161
  return text_hint, save_path, audio_file_pth
162
 
163
  # Gradio interface setup
164
  with gr.Blocks(gr.themes.Glass()) as demo:
165
+ with gr.Row():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  with gr.Column():
167
  input_text_gr = gr.Textbox(
168
  label="Create This",
 
182
  sources=["upload"],
183
  )
184
  voice_name_gr = gr.Textbox(
185
+ label="Your name",
186
  value="Sam"
187
  )
188
+ order_gr = gr.Textbox(
189
+ label="Your order",
190
+ value="Sample Order",
191
+ )
192
  customer_email_gr = gr.Textbox(
193
  label="Your Email",
194
  info="We'll send you a downloadable file to this email address."
 
200
  audio_gr = gr.Audio(label="Replicated Sound", autoplay=True)
201
  ref_audio_gr = gr.Audio(label="Original Audio Used ")
202
 
203
+ tts_button.click(predict, [input_text_gr, style_gr, ref_gr, voice_name_gr, customer_email_gr, order_gr], outputs=[out_text_gr, audio_gr, ref_audio_gr])
 
 
 
 
 
 
 
 
 
 
 
 
204
 
205
  demo.queue()
206
  demo.launch(debug=True, show_api=False, share=args.share)
 
210
  audio .btn-container {display: none}
211
  """
212
 
213
+ demo.add_css(css)