Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,68 +1,65 @@
|
|
1 |
-
# Downloading files from the demo repo
|
2 |
import os
|
3 |
import gradio as gr
|
4 |
-
import os
|
5 |
import torch
|
6 |
import pandas as pd
|
7 |
from PIL import Image
|
8 |
|
9 |
|
10 |
-
|
11 |
def load_example(prompt, img0):
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
table1 = pd.DataFrame({'Comparison': ["All the four images share a common theme of a man involved in some form of reading exercise while wearing headphones and a microphone, recorded in an indoor setting. The subjects of the images predominantly include a man, headphones, and a reading material. The artistic styles differ, as the images encompass illustrations, vector art, and a photo. The man's attire varies across the images, sometimes dressed casually in a hoodie and jeans, and other times more formally in a blue shirt and pants. The reading materials also vary, including a book and a newspaper, and the surrounding environments change, such as a simple chair setting, a room, a plane, and an unidentified indoor setting."], 'Image1': ["This is a pen and ink cartoon-style illustration for a storybook. It depicts a young man wearing a hoodie, jeans, and headphones, sitting indoors on a chair with a backrest. He is reading a book closely in front of a microphone, but there's no visible title on the book. The colors in the image are green, blue, black and white. His expression is neutral and he is not performing multiple tasks. The image depicts a positive mood."], 'Image2': ["The image is a centered, landscape digital sketch art. It depicts an indoor scene of a man sitting alone on a folding chair, engrossed in reading a newspaper. He is dressed in a hoodie and jeans, and wears a pair of headphones. There are no notable expressions on his face. The setting is clean and minimal with no other objects or furniture around. No one else is in the picture. The dominant colors are white, black, and gray."], 'Image3': ["This is a centered-shot photo of a young man in a blue shirt and pants sitting alone in an airplane cockpit, presumably mid-flight. The man, wearing headphones and a microphone, is seen writing on lined paper with a ballpoint pen, indicating communication."], 'Image4': ["This is a vector art cartoon character portrait. The image presents an indoor setting where a man is sitting in a chair. He is spotted wearing a hoodie and a set of headphones, presumably for communication, given the presence of a microphone near him. The man is deeply engrossed in reading a newspaper. The color palette is primarily orange, black and white, hinting at a serene and positive atmosphere. As per the context, the man appears to be alone in the room and comfortable in his solitude."]})
|
37 |
-
return [*splitted_images, table1]
|
38 |
|
39 |
|
40 |
with gr.Blocks() as demo:
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
|
67 |
if __name__ == "__main__":
|
68 |
demo.launch()
|
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
|
|
3 |
import torch
|
4 |
import pandas as pd
|
5 |
from PIL import Image
|
6 |
|
7 |
|
|
|
8 |
def load_example(prompt, img0):
|
9 |
+
img0 = Image.open(img0)
|
10 |
+
width, height = img0.size
|
11 |
+
single_width = width // 2
|
12 |
+
single_height = height // 2
|
13 |
+
splitted_images = []
|
14 |
+
for i in range(4):
|
15 |
+
x = i % 2 * single_width
|
16 |
+
y = i // 2 * single_height
|
17 |
+
single_filename = f'img{i+1}.jpg'
|
18 |
+
splitted_images.append(single_filename)
|
19 |
+
img0.crop((x, y, x + single_width, y + single_height)).save(single_filename, quality=100)
|
20 |
+
|
21 |
+
if prompt == "A young chef is cooking the dinner for his parents":
|
22 |
+
table1 = pd.DataFrame({
|
23 |
+
'Comparison': ["The four images are all related to cooking/food preparation. They all have a natural lighting source, and the emotions depicted in all of them are happy. The differences among these images include medium (vector art, stock photo), focus on subject (a boy, a father, a mother), availability of ingredients, kitchen size, utensils being used, whether family members are wearing aprons, whether the family members are cooking individually or collectively, etc."],
|
24 |
+
'Image1': ["In this cartoon illustration, a man with a chef's hat is cooking in a kitchen. Two children are helping him. There are no parents present. The kitchen is small and has a stove, pots, pans, and utensils. The man is using a pan to cook. The children are not wearing aprons. The overall mood is happy. The kitchen has a bright natural lighting."],
|
25 |
+
'Image2': ["In the photo, a young boy is wearing a white chef's hat and preparing vegetables on the kitchen counter. He has a serious look on his face but seems happy. He is holding a spoon, fork, and knife. The stove is not turned on. The image shows a headshot of him in natural lighting."],
|
26 |
+
'Image3': ["In this vector art image with natural lighting, a man, a woman, and a child are happily preparing sausages together. The chef is male and holding cooking utensils. There are ingredients on the counter behind them. The family members are wearing aprons but there are no kitchen appliances being used. The lighting is bright and there are no decorations or artwork on the walls."],
|
27 |
+
'Image4': ["This is a vector art of a happy family of three preparing food in the kitchen under natural lighting. The father, a male chef, is holding cooking utensils while cooking meat and vegetables on the stove. Ingredients are visible on the counter and in the background. The spacious kitchen has pots, pans, bowls, spoons, spatulas being used. The mother and children are also cooking together without aprons or chef hats. All family members are focused and joyful while cooking together."]
|
28 |
+
})
|
29 |
+
return splitted_images + [table1]
|
30 |
+
|
31 |
+
# Add more conditions as needed
|
32 |
+
return splitted_images + [None]
|
|
|
|
|
33 |
|
34 |
|
35 |
with gr.Blocks() as demo:
|
36 |
+
with gr.Row():
|
37 |
+
prompt = gr.Textbox(label="Text Prompt")
|
38 |
+
with gr.Row():
|
39 |
+
img0 = gr.Image(label="Input Image", type="filepath")
|
40 |
+
with gr.Row():
|
41 |
+
img1 = gr.Image(label="Image 1", type="filepath")
|
42 |
+
img2 = gr.Image(label="Image 2", type="filepath")
|
43 |
+
img3 = gr.Image(label="Image 3", type="filepath")
|
44 |
+
img4 = gr.Image(label="Image 4", type="filepath")
|
45 |
+
gr.Markdown("""<h1 style="text-align: center;">Summary Caption</h1>""")
|
46 |
+
table1 = gr.Dataframe(
|
47 |
+
headers=["Comparison", "Image 1", "Image 2", "Image 3", "Image 4"],
|
48 |
+
datatype=["str", "str", "str", "str", "str"],
|
49 |
+
interactive=True
|
50 |
+
)
|
51 |
+
gr.Examples(
|
52 |
+
examples=[
|
53 |
+
["A young chef is cooking the dinner for his parents", "demo1.jpg"],
|
54 |
+
["Young man and woman walking on a sunny beach, the sun is visible in the frame, on a white background", "demo2.jpg"],
|
55 |
+
["Black female, hair stylist, designing her room", "demo3.jpg"],
|
56 |
+
["Use plastic that is durable rather than the one that breaks soon.", "demo4.jpg"],
|
57 |
+
["An interpreter in a booth with headphones and microphones, reading notes, listening and speaking", "demo5.jpg"]
|
58 |
+
],
|
59 |
+
inputs=[prompt, img0],
|
60 |
+
outputs=[img1, img2, img3, img4, table1],
|
61 |
+
fn=load_example
|
62 |
+
)
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
demo.launch()
|