Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -31,28 +31,31 @@ print(f'Loading info of Ovis-U1:\n{loading_info}')
|
|
31 |
model = model.eval().to("cuda")
|
32 |
model = model.to(torch.bfloat16)
|
33 |
|
34 |
-
def set_global_seed(seed: int = 42):
|
35 |
random.seed(seed)
|
36 |
np.random.seed(seed)
|
37 |
torch.manual_seed(seed)
|
38 |
torch.cuda.manual_seed_all(seed)
|
39 |
|
40 |
-
def randomize_seed_fn(seed: int, randomize: bool) -> int:
|
41 |
return random.randint(0, MAX_SEED) if randomize else seed
|
42 |
|
43 |
@spaces.GPU(duration=20)
|
44 |
def process_txt_to_img(prompt: str, height: int, width: int, steps: int, final_seed: int, guidance_scale: float, progress: gr.Progress = gr.Progress(track_tqdm=True)) -> list[Image.Image]:
|
|
|
45 |
set_global_seed(final_seed)
|
46 |
images = pipe_t2i(model, prompt, height, width, steps, cfg=guidance_scale, seed=final_seed)
|
47 |
return images
|
48 |
|
49 |
@spaces.GPU(duration=20)
|
50 |
def process_img_to_txt(prompt: str, img: Image.Image, progress: gr.Progress = gr.Progress(track_tqdm=True)) -> str:
|
|
|
51 |
output_text = pipe_txt_gen(model, img, prompt)
|
52 |
return output_text
|
53 |
|
54 |
@spaces.GPU(duration=20)
|
55 |
def process_img_txt_to_img(prompt: str, img: Image.Image, steps: int, final_seed: int, txt_cfg: float, img_cfg: float, progress: gr.Progress = gr.Progress(track_tqdm=True)) -> list[Image.Image]:
|
|
|
56 |
set_global_seed(final_seed)
|
57 |
images = pipe_img_edit(model, img, prompt, steps, txt_cfg, img_cfg, seed=final_seed)
|
58 |
return images
|
@@ -206,8 +209,7 @@ with gr.Blocks(title="Ovis-U1-3B") as demo:
|
|
206 |
output_text = gr.Textbox(label="Generated Text", visible=False, lines=5, interactive=False)
|
207 |
|
208 |
@spaces.GPU(duration=20)
|
209 |
-
def run_img_txt_to_img_tab(prompt, img, steps, seed, txt_cfg, img_cfg, progress=gr.Progress(track_tqdm=True)):
|
210 |
-
"""Use Ovis-U1-3B to modify an image. Supply Image and Text Prompt"""
|
211 |
if img is None:
|
212 |
return (
|
213 |
gr.update(value=[], visible=False),
|
@@ -221,7 +223,7 @@ with gr.Blocks(title="Ovis-U1-3B") as demo:
|
|
221 |
)
|
222 |
|
223 |
@spaces.GPU(duration=20)
|
224 |
-
def run_txt_to_img_tab(prompt, height, width, steps, seed, guidance, progress=gr.Progress(track_tqdm=True)):
|
225 |
"""Use Ovis-U1-3B to generate an Image."""
|
226 |
# Seed is already finalized by the randomize_seed_fn in the click chain
|
227 |
imgs = process_txt_to_img(prompt, height, width, steps, seed, guidance, progress=progress)
|
@@ -231,7 +233,7 @@ with gr.Blocks(title="Ovis-U1-3B") as demo:
|
|
231 |
)
|
232 |
|
233 |
@spaces.GPU(duration=20)
|
234 |
-
def run_img_to_txt_tab(img, prompt, progress=gr.Progress(track_tqdm=True)):
|
235 |
"""User Ovis-U1-3B to understand an Image (Vision processing)"""
|
236 |
if img is None:
|
237 |
return (
|
|
|
31 |
model = model.eval().to("cuda")
|
32 |
model = model.to(torch.bfloat16)
|
33 |
|
34 |
+
def set_global_seed(seed: int = 42,show_api=False):
|
35 |
random.seed(seed)
|
36 |
np.random.seed(seed)
|
37 |
torch.manual_seed(seed)
|
38 |
torch.cuda.manual_seed_all(seed)
|
39 |
|
40 |
+
def randomize_seed_fn(seed: int, randomize: bool,show_api=False) -> int:
|
41 |
return random.randint(0, MAX_SEED) if randomize else seed
|
42 |
|
43 |
@spaces.GPU(duration=20)
|
44 |
def process_txt_to_img(prompt: str, height: int, width: int, steps: int, final_seed: int, guidance_scale: float, progress: gr.Progress = gr.Progress(track_tqdm=True)) -> list[Image.Image]:
|
45 |
+
"""Use Ovis-U1-3B to generate an image. Supply a Text Prompt"""
|
46 |
set_global_seed(final_seed)
|
47 |
images = pipe_t2i(model, prompt, height, width, steps, cfg=guidance_scale, seed=final_seed)
|
48 |
return images
|
49 |
|
50 |
@spaces.GPU(duration=20)
|
51 |
def process_img_to_txt(prompt: str, img: Image.Image, progress: gr.Progress = gr.Progress(track_tqdm=True)) -> str:
|
52 |
+
"""Use Ovis-U1-3B to analyse an Image"""
|
53 |
output_text = pipe_txt_gen(model, img, prompt)
|
54 |
return output_text
|
55 |
|
56 |
@spaces.GPU(duration=20)
|
57 |
def process_img_txt_to_img(prompt: str, img: Image.Image, steps: int, final_seed: int, txt_cfg: float, img_cfg: float, progress: gr.Progress = gr.Progress(track_tqdm=True)) -> list[Image.Image]:
|
58 |
+
"""Use Ovis-U1-3B to modify an Image. Supply an Image URL and a Text Prompt (e.g. 'ghiblify', 'low-poly 3d render', 'replace house with car'"""
|
59 |
set_global_seed(final_seed)
|
60 |
images = pipe_img_edit(model, img, prompt, steps, txt_cfg, img_cfg, seed=final_seed)
|
61 |
return images
|
|
|
209 |
output_text = gr.Textbox(label="Generated Text", visible=False, lines=5, interactive=False)
|
210 |
|
211 |
@spaces.GPU(duration=20)
|
212 |
+
def run_img_txt_to_img_tab(prompt, img, steps, seed, txt_cfg, img_cfg, progress=gr.Progress(track_tqdm=True),show_api=False):
|
|
|
213 |
if img is None:
|
214 |
return (
|
215 |
gr.update(value=[], visible=False),
|
|
|
223 |
)
|
224 |
|
225 |
@spaces.GPU(duration=20)
|
226 |
+
def run_txt_to_img_tab(prompt, height, width, steps, seed, guidance, progress=gr.Progress(track_tqdm=True),show_api=False):
|
227 |
"""Use Ovis-U1-3B to generate an Image."""
|
228 |
# Seed is already finalized by the randomize_seed_fn in the click chain
|
229 |
imgs = process_txt_to_img(prompt, height, width, steps, seed, guidance, progress=progress)
|
|
|
233 |
)
|
234 |
|
235 |
@spaces.GPU(duration=20)
|
236 |
+
def run_img_to_txt_tab(img, prompt, progress=gr.Progress(track_tqdm=True),show_api=False):
|
237 |
"""User Ovis-U1-3B to understand an Image (Vision processing)"""
|
238 |
if img is None:
|
239 |
return (
|