Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -36,7 +36,7 @@ sr_model.load_weights(f'weights/RealESRGAN_x2.pth', download=False)
|
|
36 |
@torch.inference_mode()
|
37 |
@spaces.GPU(duration=120)
|
38 |
# Multimodal Understanding function
|
39 |
-
def multimodal_understanding(image, question, seed, top_p, temperature):
|
40 |
# Clear CUDA cache before generating
|
41 |
torch.cuda.empty_cache()
|
42 |
|
@@ -86,7 +86,8 @@ def generate(input_ids,
|
|
86 |
parallel_size: int = 5,
|
87 |
cfg_weight: float = 5,
|
88 |
image_token_num_per_image: int = 576,
|
89 |
-
patch_size: int = 16
|
|
|
90 |
# Clear CUDA cache before generating
|
91 |
torch.cuda.empty_cache()
|
92 |
|
@@ -141,7 +142,8 @@ def unpack(dec, width, height, parallel_size=5):
|
|
141 |
def generate_image(prompt,
|
142 |
seed=None,
|
143 |
guidance=5,
|
144 |
-
t2i_temperature=1.0
|
|
|
145 |
# Clear CUDA cache and avoid tracking gradients
|
146 |
torch.cuda.empty_cache()
|
147 |
# Set the seed for reproducible results
|
@@ -196,61 +198,66 @@ def image_upsample(img: Image.Image) -> Image.Image:
|
|
196 |
|
197 |
|
198 |
# Gradio interface
|
199 |
-
|
200 |
-
|
201 |
-
|
|
|
|
|
|
|
|
|
202 |
image_input = gr.Image()
|
203 |
with gr.Column():
|
204 |
question_input = gr.Textbox(label="Question")
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
|
|
|
|
|
|
222 |
],
|
223 |
-
|
224 |
-
|
225 |
-
)
|
226 |
|
227 |
-
|
228 |
-
|
229 |
|
|
|
230 |
|
|
|
231 |
|
232 |
-
|
233 |
-
cfg_weight_input = gr.Slider(minimum=1, maximum=10, value=5, step=0.5, label="CFG Weight")
|
234 |
-
t2i_temperature = gr.Slider(minimum=0, maximum=1, value=1.0, step=0.05, label="temperature")
|
235 |
-
|
236 |
-
prompt_input = gr.Textbox(label="Prompt. (Prompt in more detail can help produce better images!")
|
237 |
-
seed_input = gr.Number(label="Seed (Optional)", precision=0, value=1234)
|
238 |
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
"
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
|
|
|
|
254 |
|
255 |
understanding_button.click(
|
256 |
multimodal_understanding,
|
|
|
36 |
@torch.inference_mode()
|
37 |
@spaces.GPU(duration=120)
|
38 |
# Multimodal Understanding function
|
39 |
+
def multimodal_understanding(image, question, seed, top_p, temperature, progress=gr.Progress(track_tqdm=True)):
|
40 |
# Clear CUDA cache before generating
|
41 |
torch.cuda.empty_cache()
|
42 |
|
|
|
86 |
parallel_size: int = 5,
|
87 |
cfg_weight: float = 5,
|
88 |
image_token_num_per_image: int = 576,
|
89 |
+
patch_size: int = 16,
|
90 |
+
progress=gr.Progress(track_tqdm=True)):
|
91 |
# Clear CUDA cache before generating
|
92 |
torch.cuda.empty_cache()
|
93 |
|
|
|
142 |
def generate_image(prompt,
|
143 |
seed=None,
|
144 |
guidance=5,
|
145 |
+
t2i_temperature=1.0,
|
146 |
+
progress=gr.Progress(track_tqdm=True)):
|
147 |
# Clear CUDA cache and avoid tracking gradients
|
148 |
torch.cuda.empty_cache()
|
149 |
# Set the seed for reproducible results
|
|
|
198 |
|
199 |
|
200 |
# Gradio interface
|
201 |
+
css = '''
|
202 |
+
.gradio-container {max-width: 960px !important}
|
203 |
+
'''
|
204 |
+
with gr.Blocks(css=css) as demo:
|
205 |
+
gr.Markdown("# Janus Pro 7B")
|
206 |
+
with gr.Tab("Multimodal Understanding"):
|
207 |
+
gr.Markdown(value="## Multimodal Understanding")
|
208 |
image_input = gr.Image()
|
209 |
with gr.Column():
|
210 |
question_input = gr.Textbox(label="Question")
|
211 |
+
|
212 |
+
understanding_button = gr.Button("Chat")
|
213 |
+
understanding_output = gr.Textbox(label="Response")
|
214 |
|
215 |
+
with gr.Accordion("Advanced options", open=False):
|
216 |
+
und_seed_input = gr.Number(label="Seed", precision=0, value=42)
|
217 |
+
top_p = gr.Slider(minimum=0, maximum=1, value=0.95, step=0.05, label="top_p")
|
218 |
+
temperature = gr.Slider(minimum=0, maximum=1, value=0.1, step=0.05, label="temperature")
|
219 |
+
|
220 |
+
examples_inpainting = gr.Examples(
|
221 |
+
label="Multimodal Understanding examples",
|
222 |
+
examples=[
|
223 |
+
[
|
224 |
+
"explain this meme",
|
225 |
+
"doge.png",
|
226 |
+
],
|
227 |
+
[
|
228 |
+
"Convert the formula into latex code.",
|
229 |
+
"equation.png",
|
230 |
+
],
|
231 |
],
|
232 |
+
inputs=[question_input, image_input],
|
233 |
+
)
|
|
|
234 |
|
235 |
+
with gr.Tab("Text-to-Image Generation"):
|
236 |
+
gr.Markdown(value="## Text-to-Image Generation")
|
237 |
|
238 |
+
prompt_input = gr.Textbox(label="Prompt. (Prompt in more detail can help produce better images!")
|
239 |
|
240 |
+
generation_button = gr.Button("Generate Images")
|
241 |
|
242 |
+
image_output = gr.Gallery(label="Generated Images", columns=2, rows=2)
|
|
|
|
|
|
|
|
|
|
|
243 |
|
244 |
+
with gr.Accordion("Advanced options", open=False):
|
245 |
+
with gr.Row():
|
246 |
+
cfg_weight_input = gr.Slider(minimum=1, maximum=10, value=5, step=0.5, label="CFG Weight")
|
247 |
+
t2i_temperature = gr.Slider(minimum=0, maximum=1, value=1.0, step=0.05, label="temperature")
|
248 |
+
seed_input = gr.Number(label="Seed (Optional)", precision=0, value=1234)
|
249 |
+
|
250 |
+
examples_t2i = gr.Examples(
|
251 |
+
label="Text to image generation examples.",
|
252 |
+
examples=[
|
253 |
+
"Master shifu racoon wearing drip attire as a street gangster.",
|
254 |
+
"The face of a beautiful girl",
|
255 |
+
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
256 |
+
"A cute and adorable baby fox with big brown eyes, autumn leaves in the background enchanting,immortal,fluffy, shiny mane,Petals,fairyism,unreal engine 5 and Octane Render,highly detailed, photorealistic, cinematic, natural colors.",
|
257 |
+
"The image features an intricately designed eye set against a circular backdrop adorned with ornate swirl patterns that evoke both realism and surrealism. At the center of attention is a strikingly vivid blue iris surrounded by delicate veins radiating outward from the pupil to create depth and intensity. The eyelashes are long and dark, casting subtle shadows on the skin around them which appears smooth yet slightly textured as if aged or weathered over time.\n\nAbove the eye, there's a stone-like structure resembling part of classical architecture, adding layers of mystery and timeless elegance to the composition. This architectural element contrasts sharply but harmoniously with the organic curves surrounding it. Below the eye lies another decorative motif reminiscent of baroque artistry, further enhancing the overall sense of eternity encapsulated within each meticulously crafted detail. \n\nOverall, the atmosphere exudes a mysterious aura intertwined seamlessly with elements suggesting timelessness, achieved through the juxtaposition of realistic textures and surreal artistic flourishes. Each component\u2014from the intricate designs framing the eye to the ancient-looking stone piece above\u2014contributes uniquely towards creating a visually captivating tableau imbued with enigmatic allure.",
|
258 |
+
],
|
259 |
+
inputs=prompt_input,
|
260 |
+
)
|
261 |
|
262 |
understanding_button.click(
|
263 |
multimodal_understanding,
|