Spanicin commited on
Commit
c3727de
1 Parent(s): a648386

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -21,6 +21,7 @@ from flask_cors import CORS, cross_origin
21
  # from flask_swagger_ui import get_swaggerui_blueprint
22
  import uuid
23
  import time
 
24
 
25
  start_time = time.time()
26
 
@@ -219,6 +220,18 @@ def translate_text(text_prompt, target_language):
219
  )
220
  return response
221
 
 
 
 
 
 
 
 
 
 
 
 
 
222
 
223
 
224
  @app.route("/run", methods=['POST'])
@@ -228,7 +241,9 @@ def generate_video():
228
  print('request:',request.method)
229
  try:
230
  if request.method == 'POST':
231
- source_image = request.files['source_image']
 
 
232
  text_prompt = request.form['text_prompt']
233
  print('Input text prompt: ',text_prompt)
234
  voice_cloning = request.form.get('voice_cloning', 'no')
@@ -245,11 +260,13 @@ def generate_video():
245
  print('preprocess selected: ',preprocess)
246
  ref_pose_video = request.files.get('ref_pose', None)
247
 
248
- if target_language != 'original_text':
249
- response = translate_text(text_prompt, target_language)
250
- # response = await translate_text_async(text_prompt, target_language)
251
- text_prompt = response.choices[0].message.content.strip()
252
-
 
 
253
  app.config['text_prompt'] = text_prompt
254
  print('Final text prompt: ',text_prompt)
255
 
 
21
  # from flask_swagger_ui import get_swaggerui_blueprint
22
  import uuid
23
  import time
24
+ from PIL import Image
25
 
26
  start_time = time.time()
27
 
 
220
  )
221
  return response
222
 
223
+ def chat_avatar(text_prompt):
224
+ response = client.chat.completions.create(
225
+ model="gpt-4o-mini",
226
+ messages=[{"role": "system", "content": "You are an interactive, conversational and helpful chatbot. Your role is to assist users by providing clear, engaging, and relevant responses based on their queries."},
227
+ {"role": "user", "content": f"Hi! I need help with something. Can you assist me with the following: {text_prompt}"},
228
+ ],
229
+ max_tokens = len(text_prompt) + 300 # Use the length of the input text
230
+ # temperature=0.3,
231
+ # stop=["Translate:", "Text:"]
232
+ )
233
+ return response
234
+
235
 
236
 
237
  @app.route("/run", methods=['POST'])
 
241
  print('request:',request.method)
242
  try:
243
  if request.method == 'POST':
244
+ # source_image = request.files['source_image']
245
+ image_path = '/home/user/app/images/avatar.jpg'
246
+ source_image = Image.open(image_path)
247
  text_prompt = request.form['text_prompt']
248
  print('Input text prompt: ',text_prompt)
249
  voice_cloning = request.form.get('voice_cloning', 'no')
 
260
  print('preprocess selected: ',preprocess)
261
  ref_pose_video = request.files.get('ref_pose', None)
262
 
263
+ # if target_language != 'original_text':
264
+ # response = translate_text(text_prompt, target_language)
265
+ # # response = await translate_text_async(text_prompt, target_language)
266
+ # text_prompt = response.choices[0].message.content.strip()
267
+
268
+ response = chat_avatar(text_prompt)
269
+ text_prompt = response.choices[0].message.content.strip()
270
  app.config['text_prompt'] = text_prompt
271
  print('Final text prompt: ',text_prompt)
272