tricktreat commited on
Commit
6310e00
1 Parent(s): 5471e91

text to video

Browse files
Files changed (3) hide show
  1. app.py +15 -7
  2. awesome_chat.py +4 -2
  3. models_server.py +9 -3
app.py CHANGED
@@ -95,14 +95,23 @@ class Client:
95
  self.add_message(message, "assistant")
96
  messages[-1][1] = message
97
  for image_url in image_urls:
98
- image_url = image_url.replace("public/", "")
99
- messages = messages + [((None, (f"public/{image_url}",)))]
 
 
 
100
  for audio_url in audio_urls:
101
- audio_url = audio_url.replace("public/", "")
102
- messages = messages + [((None, (f"public/{audio_url}",)))]
 
 
 
103
  for video_url in video_urls:
104
- video_url = video_url.replace("public/", "")
105
- messages = messages + [((None, (f"public/{video_url}",)))]
 
 
 
106
  return messages
107
 
108
  with gr.Blocks() as demo:
@@ -168,7 +177,6 @@ with gr.Blocks() as demo:
168
  "Please generate a canny image based on /examples/f.jpg",
169
  "show me a joke and an image of cat",
170
  "what is in the examples/a.jpg",
171
- "generate a video and audio about a dog is running on the grass",
172
  "based on the /examples/a.jpg, please generate a video and audio",
173
  "based on pose of /examples/d.jpg and content of /examples/e.jpg, please show me a new image",
174
  ],
 
95
  self.add_message(message, "assistant")
96
  messages[-1][1] = message
97
  for image_url in image_urls:
98
+ if not image_url.startswith("http"):
99
+ image_url = image_url.replace("public/", "")
100
+ messages = messages + [((None, (f"public/{image_url}",)))]
101
+ else:
102
+ messages = messages + [((None, (f"{image_url}",)))]
103
  for audio_url in audio_urls:
104
+ if not audio_url.startswith("http"):
105
+ audio_url = audio_url.replace("public/", "")
106
+ messages = messages + [((None, (f"public/{audio_url}",)))]
107
+ else:
108
+ messages = messages + [((None, (f"{audio_url}",)))]
109
  for video_url in video_urls:
110
+ if not video_url.startswith("http"):
111
+ video_url = video_url.replace("public/", "")
112
+ messages = messages + [((None, (f"public/{video_url}",)))]
113
+ else:
114
+ messages = messages + [((None, (f"{video_url}",)))]
115
  return messages
116
 
117
  with gr.Blocks() as demo:
 
177
  "Please generate a canny image based on /examples/f.jpg",
178
  "show me a joke and an image of cat",
179
  "what is in the examples/a.jpg",
 
180
  "based on the /examples/a.jpg, please generate a video and audio",
181
  "based on pose of /examples/d.jpg and content of /examples/e.jpg, please show me a new image",
182
  ],
awesome_chat.py CHANGED
@@ -835,12 +835,14 @@ def chat_huggingface(messages, openaikey = None, huggingfacetoken = None, return
835
  logger.info("*"*80)
836
  logger.info(f"input: {input}")
837
 
838
- task_str = parse_task(context, input, openaikey).strip()
839
  logger.info(task_str)
840
 
841
  if "error" in task_str:
842
  return {"message": "You exceeded your current quota, please check your plan and billing details."}
843
-
 
 
844
  if task_str == "[]": # using LLM response for empty task
845
  record_case(success=False, **{"input": input, "task": [], "reason": "task parsing fail: empty", "op": "chitchat"})
846
  response = chitchat(messages, openaikey)
 
835
  logger.info("*"*80)
836
  logger.info(f"input: {input}")
837
 
838
+ task_str = parse_task(context, input, openaikey)
839
  logger.info(task_str)
840
 
841
  if "error" in task_str:
842
  return {"message": "You exceeded your current quota, please check your plan and billing details."}
843
+ else:
844
+ task_str = task_str.strip()
845
+
846
  if task_str == "[]": # using LLM response for empty task
847
  record_case(success=False, **{"input": input, "task": [], "reason": "task parsing fail: empty", "op": "chitchat"})
848
  response = chitchat(messages, openaikey)
models_server.py CHANGED
@@ -374,10 +374,16 @@ def models(model_id, data):
374
  # pipe.enable_model_cpu_offload()
375
  prompt = data["text"]
376
  video_frames = pipe(prompt, num_inference_steps=50, num_frames=40).frames
377
- video_path = export_to_video(video_frames)
378
  file_name = str(uuid.uuid4())[:4]
379
- os.system(f"LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/ffmpeg -i {video_path} -vcodec libx264 public/videos/{file_name}.mp4")
380
- result = {"path": f"/videos/{file_name}.mp4"}
 
 
 
 
 
 
 
381
 
382
  # controlnet
383
  if model_id.startswith("lllyasviel/sd-controlnet-"):
 
374
  # pipe.enable_model_cpu_offload()
375
  prompt = data["text"]
376
  video_frames = pipe(prompt, num_inference_steps=50, num_frames=40).frames
 
377
  file_name = str(uuid.uuid4())[:4]
378
+ video_path = export_to_video(video_frames, f"public/videos/{file_name}.mp4")
379
+
380
+ new_file_name = str(uuid.uuid4())[:4]
381
+ os.system(f"ffmpeg -i {video_path} -vcodec libx264 public/videos/{new_file_name}.mp4")
382
+
383
+ if os.path.exists(f"public/videos/{new_file_name}.mp4"):
384
+ result = {"path": f"/videos/{new_file_name}.mp4"}
385
+ else:
386
+ result = {"path": f"/videos/{file_name}.mp4"}
387
 
388
  # controlnet
389
  if model_id.startswith("lllyasviel/sd-controlnet-"):