Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
-
from PIL import Image
|
| 4 |
-
import os
|
| 5 |
-
|
| 6 |
-
# Define the path to the CSV file in the current directory
|
| 7 |
-
csv_file_path = "csv_data/descriptions.csv"
|
| 8 |
-
|
| 9 |
-
# Initialize an empty DataFrame to store the data
|
| 10 |
-
data = pd.DataFrame(columns=["Image", "Description 1", "Description 2", "Description 3"])
|
| 11 |
|
| 12 |
# Function to handle the user's input and store it in the DataFrame
|
| 13 |
-
def describe_image(image, desc1, desc2, desc3):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
return None # Return None for no specific output
|
| 18 |
|
| 19 |
iface = gr.Interface(
|
|
@@ -22,7 +20,8 @@ iface = gr.Interface(
|
|
| 22 |
gr.Image(type="pil", label="Upload an Image"),
|
| 23 |
"text",
|
| 24 |
"text",
|
| 25 |
-
"text"
|
|
|
|
| 26 |
],
|
| 27 |
outputs=gr.Info("Data saved successfully"), # Display the success message
|
| 28 |
live=False,
|
|
@@ -31,4 +30,4 @@ iface = gr.Interface(
|
|
| 31 |
allow_flagging=False,
|
| 32 |
)
|
| 33 |
|
| 34 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# Function to handle the user's input and store it in the DataFrame
|
| 5 |
+
def describe_image(image, desc1, desc2, desc3, csv_file_path):
|
| 6 |
+
# Check if the file exists, and if not, create it
|
| 7 |
+
if not pd.api.types.is_file_like(csv_file_path):
|
| 8 |
+
data = pd.DataFrame(columns=["Image", "Description 1", "Description 2", "Description 3"])
|
| 9 |
+
else:
|
| 10 |
+
data = pd.read_csv(csv_file_path)
|
| 11 |
+
|
| 12 |
+
data = data.append({"Image": image, "Description 1": desc1, "Description 2": desc2, "Description 3": desc3},
|
| 13 |
+
ignore_index=True)
|
| 14 |
+
data.to_csv(csv_file_path, index=False) # Save the data to the specified CSV file
|
| 15 |
return None # Return None for no specific output
|
| 16 |
|
| 17 |
iface = gr.Interface(
|
|
|
|
| 20 |
gr.Image(type="pil", label="Upload an Image"),
|
| 21 |
"text",
|
| 22 |
"text",
|
| 23 |
+
"text",
|
| 24 |
+
"text" # Add an input field for specifying the CSV file path
|
| 25 |
],
|
| 26 |
outputs=gr.Info("Data saved successfully"), # Display the success message
|
| 27 |
live=False,
|
|
|
|
| 30 |
allow_flagging=False,
|
| 31 |
)
|
| 32 |
|
| 33 |
+
iface.launch()
|