shrijayan commited on
Commit
9273446
1 Parent(s): 5a987e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -21
app.py CHANGED
@@ -1,23 +1,43 @@
 
 
 
 
 
1
  import gradio as gr
2
 
3
- # Define a function that takes image and text inputs and returns a video result
4
- def process_input(image, text):
5
- # Add your processing logic here to generate a video
6
- # For simplicity, let's just return a sample video URL
7
- video_url = "https://www.example.com/sample_video.mp4"
8
- return video_url
9
-
10
- # Define the Gradio interface
11
- iface = gr.Interface(
12
- fn=process_input, # Function to be called with inputs
13
- inputs=[
14
- gr.Image(type="pil", label="Upload an image"), # Image input
15
- gr.Textbox(label="Enter some text"), # Text input
16
- ],
17
- outputs=gr.Video(label="Processed Video"), # Video output
18
- live=True,
19
- title="Image and Text to Video Processor",
20
- )
21
-
22
- # Launch the Gradio interface
23
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # generate_video.py
2
+
3
+ from gtts import gTTS
4
+ from pydub import AudioSegment
5
+ import cv2
6
  import gradio as gr
7
 
8
+ def text_to_wav(text, file_name):
9
+ language = 'en'
10
+ tts = gTTS(text=text, lang=language, slow=False)
11
+ tts.save(file_name)
12
+
13
+ def generate_video(input_image, input_text):
14
+ text_file = "input_audio.wav"
15
+ video_file = "/path/to/generated_video.mp4"
16
+
17
+ text_to_wav(input_text, text_file)
18
+
19
+ audio = AudioSegment.from_file(text_file)
20
+ duration_seconds = len(audio) / 1000.0
21
+
22
+ img = cv2.imread(input_image)
23
+
24
+ fps = 60
25
+ video_duration_seconds = round(duration_seconds) * 3
26
+
27
+ video = cv2.VideoWriter(video_file, cv2.VideoWriter_fourcc(*'mp4v'), fps, (img.shape[1], img.shape[0]))
28
+
29
+ for _ in range(int(fps * video_duration_seconds)):
30
+ video.write(img)
31
+
32
+ video.release()
33
+
34
+ return video_file
35
+
36
+ if __name__ == "__main__":
37
+ iface = gr.Interface(
38
+ fn=generate_video,
39
+ inputs=["image", "text"],
40
+ outputs="video",
41
+ )
42
+
43
+ iface.launch(share=True)