import gradio as gr from download import TDLALL, IDLALL # Import your TikTok downloader methods from sendT import sendTelmain # Import Telegram bot sending logic import os # Function to handle downloading and returning video file path def download_video(url): IDLALL() # Initialize download (assuming this sets up any necessary configurations) TDLALL(url) # Download the video using the URL # Assuming the downloaded video is saved in './vids/' directory video_files = os.listdir('./vids/') if video_files: latest_video = './vids/' + video_files[-1] # Get the latest downloaded video return latest_video # Return the path to the video file return None # Gradio Interface def interface(url): video_path = download_video(url) if video_path: # Return the video for preview in Gradio return video_path else: return "Error downloading video." def send_to_telegram(): # Send the video to the Telegram bot sendTelmain() return "Videos sent to Telegram bot." # Create Gradio interface with gr.Blocks() as demo: gr.Markdown("# TikTok Video Downloader") with gr.Row(): url_input = gr.Textbox(label="TikTok Video URL", placeholder="Enter TikTok video URL here") with gr.Row(): download_button = gr.Button("Download Video") send_button = gr.Button("Send to Telegram Bot") with gr.Row(): video_preview = gr.Video(label="Downloaded Video Preview") download_button.click(fn=interface, inputs=url_input, outputs=video_preview) send_button.click(fn=send_to_telegram, inputs=None, outputs=None) # Launch Gradio App if __name__ == "__main__": demo.launch()