Spaces:
Running
Running
commit
Browse files- app.py +50 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Load metadata
|
| 7 |
+
df = pd.read_csv('preferences.csv')
|
| 8 |
+
|
| 9 |
+
# Function to display image pairs
|
| 10 |
+
def show_image_pair(pair_id):
|
| 11 |
+
record = df[df['pair_id'] == pair_id].iloc[0]
|
| 12 |
+
img1_path = record['image1']
|
| 13 |
+
img2_path = record['image2']
|
| 14 |
+
img1 = Image.open(img1_path)
|
| 15 |
+
img2 = Image.open(img2_path)
|
| 16 |
+
return img1, img2, record['prompt'], record['label1'], record['label1_score'], record['label2'], record['label2_score'], record['label3'], record['label3_score']
|
| 17 |
+
|
| 18 |
+
# Create dropdown options
|
| 19 |
+
pair_ids = df['pair_id'].tolist()
|
| 20 |
+
|
| 21 |
+
# Define Gradio Interface
|
| 22 |
+
with gr.Blocks() as demo:
|
| 23 |
+
gr.Markdown("# MID-Space Dataset Viewer")
|
| 24 |
+
with gr.Row():
|
| 25 |
+
with gr.Column():
|
| 26 |
+
pair_id_input = gr.Dropdown(label="Select Pair ID", choices=pair_ids, value=pair_ids[0])
|
| 27 |
+
show_button = gr.Button("Show Image Pair")
|
| 28 |
+
with gr.Column():
|
| 29 |
+
img1 = gr.Image(label="Image 1")
|
| 30 |
+
img2 = gr.Image(label="Image 2")
|
| 31 |
+
with gr.Row():
|
| 32 |
+
prompt = gr.Textbox(label="Prompt", interactive=False)
|
| 33 |
+
with gr.Row():
|
| 34 |
+
label1 = gr.Textbox(label="Label 1", interactive=False)
|
| 35 |
+
label1_score = gr.Number(label="Label 1 Score", interactive=False)
|
| 36 |
+
with gr.Row():
|
| 37 |
+
label2 = gr.Textbox(label="Label 2", interactive=False)
|
| 38 |
+
label2_score = gr.Number(label="Label 2 Score", interactive=False)
|
| 39 |
+
with gr.Row():
|
| 40 |
+
label3 = gr.Textbox(label="Label 3", interactive=False)
|
| 41 |
+
label3_score = gr.Number(label="Label 3 Score", interactive=False)
|
| 42 |
+
|
| 43 |
+
show_button.click(
|
| 44 |
+
show_image_pair,
|
| 45 |
+
inputs=[pair_id_input],
|
| 46 |
+
outputs=[img1, img2, prompt, label1, label1_score, label2, label2_score, label3, label3_score]
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
if __name__ == "__main__":
|
| 50 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pandas
|
| 3 |
+
pillow
|