Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
else:
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,14 +38,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,
|
| 28 |
title="Image Description App",
|
| 29 |
description="Upload an image and provide three descriptions for it.",
|
| 30 |
allow_flagging=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
)
|
| 32 |
|
| 33 |
-
iface.launch()
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
+
from pydrive.auth import GoogleAuth
|
| 5 |
+
from pydrive.drive import GoogleDrive
|
| 6 |
|
| 7 |
+
# Load credentials from environment variables
|
| 8 |
+
gauth = GoogleAuth()
|
| 9 |
+
gauth.LocalWebserverAuth()
|
| 10 |
+
|
| 11 |
+
# Initialize Google Drive
|
| 12 |
+
drive = GoogleDrive(gauth)
|
| 13 |
+
|
| 14 |
+
# Function to handle the user's input and store it in a Google Drive file
|
| 15 |
+
def describe_image(image, desc1, desc2, desc3):
|
| 16 |
+
data = pd.DataFrame(columns=["Image", "Description 1", "Description 2", "Description 3"])
|
| 17 |
+
data = data.append({"Image": image, "Description 1": desc1, "Description 2": desc2, "Description 3": desc3}, ignore_index=True)
|
| 18 |
+
|
| 19 |
+
# Create or get a reference to the file on Google Drive
|
| 20 |
+
file_list = drive.ListFile({'q': "'" + os.environ.get("GDRIVE_FOLDER_ID") + "' in parents and trashed=false"}).GetList()
|
| 21 |
+
for file in file_list:
|
| 22 |
+
if file['title'] == os.environ.get("CSV_FILENAME"):
|
| 23 |
+
gdrive_file = file
|
| 24 |
+
break
|
| 25 |
else:
|
| 26 |
+
gdrive_file = drive.CreateFile({'title': os.environ.get("CSV_FILENAME"), "parents": [{"kind": "drive#fileLink", "id": os.environ.get("GDRIVE_FOLDER_ID")}]})
|
| 27 |
+
|
| 28 |
+
# Write the data to the file and save it on Google Drive
|
| 29 |
+
data.to_csv('temp.csv', index=False)
|
| 30 |
+
gdrive_file.SetContentFile('temp.csv')
|
| 31 |
+
gdrive_file.Upload()
|
| 32 |
|
|
|
|
|
|
|
|
|
|
| 33 |
return None # Return None for no specific output
|
| 34 |
|
| 35 |
iface = gr.Interface(
|
|
|
|
| 38 |
gr.Image(type="pil", label="Upload an Image"),
|
| 39 |
"text",
|
| 40 |
"text",
|
| 41 |
+
"text"
|
|
|
|
| 42 |
],
|
| 43 |
+
outputs=gr.Info("Data saved successfully on Google Drive"), # Display the success message
|
| 44 |
live=False,
|
| 45 |
title="Image Description App",
|
| 46 |
description="Upload an image and provide three descriptions for it.",
|
| 47 |
allow_flagging=False,
|
| 48 |
+
theme=gr.themes.Base(primary_hue="green").set(
|
| 49 |
+
button_primary_background_fill="*primary_400",
|
| 50 |
+
button_primary_background_fill_hover="*primary_300",
|
| 51 |
+
)
|
| 52 |
)
|
| 53 |
|
| 54 |
+
iface.launch()
|