how add public link in this: import gradio as gr import os import cv2 import numpy as np…
- User
how add public link in this: import gradio as gr import os import cv2 import numpy as np from moviepy.editor import *
from diffusers import StableDiffusionInstructPix2PixPipeline import torch from PIL import Image, ImageOps import time import psutil import math import random
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained("timbrooks/instruct-pix2pix", torch_dtype=torch.float16, safety_checker=None)
device = "GPU 🔥" if torch.cuda.is_available() else "CPU 🥶"
if torch.cuda.is_available(): pipe = pipe.to("cuda")
def pix2pix( input_image: Image.Image, instruction: str, steps: int, seed: int, text_cfg_scale: float, image_cfg_scale: float, ):
codewidth, height = input_image.size factor = 512 / max(width, height) factor = math.ceil(min(width, height) * factor / 64) * 64 / min(width, height) width = int((width * factor) // 64) * 64 height = int((height * factor) // 64) * 64 input_image = ImageOps.fit(input_image, (width, height), method=Image.Resampling.LANCZOS) if instruction == "": return [input_image, seed] generator = torch.manual_seed(seed) edited_image = pipe( instruction, image=input_image, guidance_scale=text_cfg_scale, image_guidance_scale=image_cfg_scale, num_inference_steps=steps, generator=generator, ).images[0] print(f"EDITED: {edited_image}") return edited_imagedef get_frames(video_in): frames = [] #resize the video clip = VideoFileClip(video_in)
code - Assistant
To add a public link for sharing or access to your Gradio app, you need to ensure that you're using the
launchmethod with theshareparameter set toTrue. This will create a publicly accessible link that you can share with others.Here's how you can modify the last line of your code to include this functionality:
Change:
pythondemo.queue(max_size=12).launch(show_api=False)To:
pythondemo.queue(max_size=12).launch(show_api=False, share=True)The complete section at the bottom should look like this:
pythonsubmit_btn.click(infer, inputs, outputs, show_api=False) demo.queue(max_size=12).launch(show_api=False, share=True)Explanation:
share=True: This sets theshareoption to , enabling public link sharing. When you run the app, it will generate a URL that you can share with anyone to access your Gradio interface.