bestroi commited on
Commit
9d2616d
·
1 Parent(s): 2ca750a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -2,6 +2,11 @@ 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"
@@ -10,9 +15,12 @@ csv_file_path = "descriptions.csv"
10
  data = []
11
 
12
  # Function to handle the user's input and store it in the list
13
- def describe_image(image, filename, copyright, description):
14
  global data
15
- data.append({"Image": image, "XML File Name": filename, "Copyright Holder": copyright, "Physichal Description": description})
 
 
 
16
  # Convert the list to a DataFrame
17
  data_df = pd.DataFrame(data)
18
  data_df.to_csv(csv_file_path, index=False) # Save the data to a CSV file in the current directory
 
2
  import pandas as pd
3
  from PIL import Image
4
  import os
5
+ import uuid
6
+
7
+ # Create a directory to store the images
8
+ image_directory = "images"
9
+ os.makedirs(image_directory, exist_ok=True)
10
 
11
  # Define the path to the CSV file in the current directory
12
  csv_file_path = "descriptions.csv"
 
15
  data = []
16
 
17
  # Function to handle the user's input and store it in the list
18
+ def describe_image(image, filename, description, copyright):
19
  global data
20
+ # Generate a unique filename for each image
21
+ image_filename = os.path.join(image_directory, f"{str(uuid.uuid4())}.jpg")
22
+ image.save(image_filename)
23
+ data.append({"Image": image_filename, "Filename": filename, "Description": description, "Copyright": copyright})
24
  # Convert the list to a DataFrame
25
  data_df = pd.DataFrame(data)
26
  data_df.to_csv(csv_file_path, index=False) # Save the data to a CSV file in the current directory