import gradio as gr import time from PIL import Image # Initialize a counter to keep track of the number of times the function is called #call_counter = 0 # Function to display different images based on the call count def generate_image(text): # Define image paths for the first call image_path = "yc01.jpg" # If the image path exists, return it; otherwise, return None if image_path: image = Image.open(image_path) return image else: return None # Function to show thumbnail def get_ytmetas(youtube_link): # Define image paths for the first and second calls image_path = ["/content/playlist.png"] # If the image path exists, return it; otherwise, return None if image_path: image = Image.open(image_path) return f"Dalton & Michael", f"Dalton Caldwell and Michael Seibel talk startups, Silicon Valley and advice for founders." #return image, "Dalton & Michael", "Dalton Caldwell and Michael Seibel talk startups, Silicon Valley and advice for founders." else: return None # Function to fine-tune a model def train_model(youtube_link, progress=gr.Progress()): time.sleep(4) return "Model successfully trained for Datlon & Michael." def my_function(x, progress=gr.Progress()): progress(0, desc="Training...") time.sleep(1) for i in progress.tqdm(range(100)): time.sleep(0.2) return "Model successfully trained for Datlon & Michael." with gr.Blocks(title = "Old Fat Boy").queue() as demo: with gr.Tab("Train"): with gr.Row(): tb_youtubelink = gr.Textbox(label="Youtube Link" ) with gr.Row(): btn_run = gr.Button("Train",variant="primary") with gr.Row(): tb_indicator = gr.Textbox(label="Output") #btn_run.click(fn=train_model,inputs=[tb_youtubelink],outputs=[tb_indicator]) btn_run.click(fn=my_function,inputs=[tb_youtubelink],outputs=[tb_indicator]) with gr.Tab("Generate"): with gr.Row(): prompt = gr.Textbox(label="Prompt" ) image_output = gr.Image(label="Image") image_button = gr.Button("Generate Image") image_button.click(generate_image, inputs=prompt, outputs=image_output) with gr.Tab("Edit"): with gr.Column(): edit_image = gr.Image(label="Generated Image") # Left --> tools with gr.Row(): # Element 1 with gr.Column(): element1 = gr.Image(label="Element1") # Drag with gr.Row(): with gr.Column(scale=1, min_width=10): gr.Markdown(value="Drag", show_label=False) with gr.Column(scale=4, min_width=10): with gr.Row(): with gr.Column(scale=1, min_width=10): enable_add_points = gr.Button("Add Points") with gr.Column(scale=1, min_width=10): undo_points = gr.Button("Reset Points") with gr.Row(): with gr.Column(scale=1, min_width=10): form_start_btn = gr.Button("Start") with gr.Column(scale=1, min_width=10): form_stop_btn = gr.Button("Stop") form_draw_interval_number = gr.Number( #value=global_state.value["draw_interval"], label="Draw Interval (steps)", interactive=True, visible=False, ) # Element 2 with gr.Column(): element1 = gr.Image(label="Element2") # Drag with gr.Row(): with gr.Column(scale=1, min_width=10): gr.Markdown(value="Drag", show_label=False) with gr.Column(scale=4, min_width=10): with gr.Row(): with gr.Column(scale=1, min_width=10): enable_add_points = gr.Button("Add Points") with gr.Column(scale=1, min_width=10): undo_points = gr.Button("Reset Points") with gr.Row(): with gr.Column(scale=1, min_width=10): form_start_btn = gr.Button("Start") with gr.Column(scale=1, min_width=10): form_stop_btn = gr.Button("Stop") form_draw_interval_number = gr.Number( #value=global_state.value["draw_interval"], label="Draw Interval (steps)", interactive=True, visible=False, ) # Element 3 with gr.Column(): element1 = gr.Image(label="Element3") # Drag with gr.Row(): with gr.Column(scale=1, min_width=10): gr.Markdown(value="Drag", show_label=False) with gr.Column(scale=4, min_width=10): with gr.Row(): with gr.Column(scale=1, min_width=10): enable_add_points = gr.Button("Add Points") with gr.Column(scale=1, min_width=10): undo_points = gr.Button("Reset Points") with gr.Row(): with gr.Column(scale=1, min_width=10): form_start_btn = gr.Button("Start") with gr.Column(scale=1, min_width=10): form_stop_btn = gr.Button("Stop") form_draw_interval_number = gr.Number( #value=global_state.value["draw_interval"], label="Draw Interval (steps)", interactive=True, visible=False, ) apply_btn = gr.Button("Apply") if __name__ == "__main__": demo.launch(share=False, debug=True, favicon_path='oldfatboy.png')