Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Function to read CSV and show preview
|
| 6 |
+
def read_csv(file):
|
| 7 |
+
df = pd.read_csv(file.name)
|
| 8 |
+
return df.head() # Show only the first 5 rows for preview
|
| 9 |
+
|
| 10 |
+
# Function to upload and display an image
|
| 11 |
+
def upload_image(image_file):
|
| 12 |
+
img = Image.open(image_file.name)
|
| 13 |
+
return img
|
| 14 |
+
|
| 15 |
+
# Function to select CSV display options (Preview or Full View)
|
| 16 |
+
def toggle_view(file, view_type):
|
| 17 |
+
df = pd.read_csv(file.name)
|
| 18 |
+
if view_type == "Preview":
|
| 19 |
+
return df.head() # Show the first 5 rows for preview
|
| 20 |
+
return df # Show the entire data
|
| 21 |
+
|
| 22 |
+
# Creating Gradio Interface
|
| 23 |
+
with gr.Blocks() as demo:
|
| 24 |
+
# Create a menu bar
|
| 25 |
+
gr.HTML("""
|
| 26 |
+
<div style="background-color:#f5f5f5;padding:10px;border-radius:5px;">
|
| 27 |
+
<h3 style="margin:0;">CSV and Image Viewer App</h3>
|
| 28 |
+
</div>
|
| 29 |
+
""")
|
| 30 |
+
|
| 31 |
+
# Image Upload Section
|
| 32 |
+
with gr.Row():
|
| 33 |
+
image_input = gr.File(label="Upload Image", type="file", file_count="single")
|
| 34 |
+
image_output = gr.Image(type="pil")
|
| 35 |
+
image_input.change(upload_image, inputs=image_input, outputs=image_output)
|
| 36 |
+
|
| 37 |
+
# CSV File Upload Section
|
| 38 |
+
with gr.Row():
|
| 39 |
+
file_input = gr.File(label="Upload CSV File", type="filepath")
|
| 40 |
+
file_output = gr.DataFrame()
|
| 41 |
+
|
| 42 |
+
# Radio buttons to select CSV view type (Preview or Full)
|
| 43 |
+
view_selector = gr.Radio(label="View Type", choices=["Preview", "Full View"], value="Preview")
|
| 44 |
+
|
| 45 |
+
file_input.change(toggle_view, inputs=[file_input, view_selector], outputs=file_output)
|
| 46 |
+
view_selector.change(toggle_view, inputs=[file_input, view_selector], outputs=file_output)
|
| 47 |
+
|
| 48 |
+
demo.launch()
|