ibrahim313 commited on
Commit
bd91662
·
verified ·
1 Parent(s): fece103

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -0
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from pyngrok import ngrok
3
+ import os
4
+ import torch
5
+ from google.colab import drive
6
+ import requests
7
+
8
+ # Ngrok authentication
9
+ ngrok.set_auth_token("2oStBdyDH75Ike6t5jLv9AeOVk2_6eX2eNR1hb9sE5APN17Ky")
10
+
11
+ # Hugging Face repository URLs
12
+ HUGGINGFACE_REPO_URL = "https://huggingface.co/spaces/ibrahim313/Lipsing/tree/main"
13
+ UPLOAD_FOLDER = '/content/testing/result_output'
14
+ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
15
+
16
+ # Function to download files from Hugging Face
17
+ def download_from_huggingface(file_path):
18
+ url = f"{HUGGINGFACE_REPO_URL}/{file_path}"
19
+ local_path = f"/content/lipsync-lab/{file_path}"
20
+ os.makedirs(os.path.dirname(local_path), exist_ok=True)
21
+ response = requests.get(url)
22
+ with open(local_path, "wb") as file:
23
+ file.write(response.content)
24
+ return local_path
25
+
26
+ # Download necessary files from Hugging Face
27
+ if not os.path.exists('/content/lipsync-lab'):
28
+ os.makedirs('/content/lipsync-lab')
29
+ download_from_huggingface("checkpoints/mobilenet.pth")
30
+ download_from_huggingface("models/wav2lip.py")
31
+ # Add any additional files needed for the model here
32
+
33
+ # Mount Google Drive (if in Colab)
34
+ if not os.path.exists('/content/drive'):
35
+ drive.mount('/content/drive')
36
+
37
+ # Define Gradio functions
38
+ def setup_environment():
39
+ # Install additional dependencies
40
+ os.system('pip install batch_face --quiet')
41
+ os.system('pip install basicsr==1.4.2 --quiet')
42
+ os.system('pip install gfpgan --quiet')
43
+ os.system('python /content/lipsync-lab/install.py')
44
+ return "Setup complete. You can now upload your files."
45
+
46
+ def upload_audio(audio_file):
47
+ if audio_file is not None:
48
+ audio_path = os.path.join(UPLOAD_FOLDER, audio_file.name)
49
+ audio_file.save(audio_path)
50
+ return f"Audio file '{audio_file.name}' uploaded successfully!"
51
+ else:
52
+ return "No audio file uploaded."
53
+
54
+ def upload_video(video_file):
55
+ if video_file is not None:
56
+ video_path = os.path.join(UPLOAD_FOLDER, video_file.name)
57
+ video_file.save(video_path)
58
+ return f"Video file '{video_file.name}' uploaded successfully!"
59
+ else:
60
+ return "No video file uploaded."
61
+
62
+ # Define the Gradio interface layout
63
+ with gr.Blocks() as app:
64
+ gr.Markdown("# AI Lip-Sync Application")
65
+
66
+ with gr.Tab("Setup"):
67
+ gr.Markdown("Click the button below to set up the environment.")
68
+ setup_button = gr.Button("Setup Environment")
69
+ setup_output = gr.Textbox(label="Setup Status")
70
+ setup_button.click(setup_environment, outputs=setup_output)
71
+
72
+ with gr.Tab("Upload Files"):
73
+ gr.Markdown("Upload your audio and video files.")
74
+ audio_file = gr.File(label="Upload Audio File")
75
+ video_file = gr.File(label="Upload Video File")
76
+ upload_audio_button = gr.Button("Upload Audio")
77
+ upload_video_button = gr.Button("Upload Video")
78
+ audio_output = gr.Textbox(label="Audio Upload Status")
79
+ video_output = gr.Textbox(label="Video Upload Status")
80
+
81
+ # Set actions for file uploads
82
+ upload_audio_button.click(upload_audio, inputs=audio_file, outputs=audio_output)
83
+ upload_video_button.click(upload_video, inputs=video_file, outputs=video_output)
84
+
85
+ with gr.Tab("Settings"):
86
+ gr.Markdown("Settings tab for further configurations (if needed).")
87
+ # Add settings options here if required
88
+
89
+ # Launch Gradio app and create ngrok tunnel
90
+ public_url = ngrok.connect(7860)
91
+ print("Public URL:", public_url)
92
+ app.launch()