bestroi commited on
Commit
f474bb1
·
1 Parent(s): f650538

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -27
app.py CHANGED
@@ -1,35 +1,19 @@
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(
@@ -40,7 +24,7 @@ iface = gr.Interface(
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.",
@@ -51,4 +35,4 @@ iface = gr.Interface(
51
  )
52
  )
53
 
54
- iface.launch()
 
 
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 = "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
+ global data
15
  data = data.append({"Image": image, "Description 1": desc1, "Description 2": desc2, "Description 3": desc3}, ignore_index=True)
16
+ data.to_csv(csv_file_path, index=False) # Save the data to a CSV file in the current directory
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  return None # Return None for no specific output
18
 
19
  iface = gr.Interface(
 
24
  "text",
25
  "text"
26
  ],
27
+ outputs=gr.Info("Data saved successfully"), # Display the success message
28
  live=False,
29
  title="Image Description App",
30
  description="Upload an image and provide three descriptions for it.",
 
35
  )
36
  )
37
 
38
+ iface.launch(share=True)