Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,33 +5,42 @@ from datasets import load_dataset
|
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
# Initialize a dataset object for your Hugging Face repository
|
| 8 |
-
dataset = load_dataset("bestroi/Images")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Function to handle the user's input and store it in the dataset
|
| 11 |
-
def describe_image(image, desc1, desc2, desc3):
|
|
|
|
| 12 |
# Convert the Gradio PIL Image object to bytes
|
| 13 |
image_bytes = io.BytesIO()
|
| 14 |
-
|
| 15 |
# Save the image in JPEG format
|
| 16 |
-
image.save(image_bytes, format="JPEG")
|
| 17 |
jpeg_data = image_bytes.getvalue()
|
| 18 |
|
| 19 |
-
data
|
|
|
|
| 20 |
"Image": jpeg_data,
|
| 21 |
"Description 1": desc1,
|
| 22 |
"Description 2": desc2,
|
| 23 |
-
"Description 3": desc3
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
# Add data to the dataset
|
| 27 |
-
dataset['train'].add_row(**data)
|
| 28 |
-
|
| 29 |
return "Data saved successfully"
|
| 30 |
|
|
|
|
| 31 |
iface = gr.Interface(
|
| 32 |
fn=describe_image,
|
| 33 |
inputs=[
|
| 34 |
gr.Image(type="pil", label="Upload an Image"),
|
|
|
|
| 35 |
"text",
|
| 36 |
"text",
|
| 37 |
"text"
|
|
@@ -47,4 +56,5 @@ iface = gr.Interface(
|
|
| 47 |
)
|
| 48 |
)
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
# Initialize a dataset object for your Hugging Face repository
|
| 8 |
+
#dataset = load_dataset("bestroi/Images")
|
| 9 |
+
|
| 10 |
+
Load the dataset from Hugging Face
|
| 11 |
+
dataset = hub.load_dataset("bestroi/Images")
|
| 12 |
+
|
| 13 |
+
# Convert the dataset to a Gradio dataset
|
| 14 |
+
gradio_dataset = gr.Dataset()
|
| 15 |
+
for row in dataset:
|
| 16 |
+
gradio_dataset.add_row(**row)
|
| 17 |
|
| 18 |
# Function to handle the user's input and store it in the dataset
|
| 19 |
+
def describe_image(image, desc1, desc2, desc3, gradio_dataset):
|
| 20 |
+
|
| 21 |
# Convert the Gradio PIL Image object to bytes
|
| 22 |
image_bytes = io.BytesIO()
|
| 23 |
+
|
| 24 |
# Save the image in JPEG format
|
| 25 |
+
image.save(image_bytes, format="JPEG")
|
| 26 |
jpeg_data = image_bytes.getvalue()
|
| 27 |
|
| 28 |
+
# Add the data to the Gradio dataset
|
| 29 |
+
gradio_dataset.add_row({
|
| 30 |
"Image": jpeg_data,
|
| 31 |
"Description 1": desc1,
|
| 32 |
"Description 2": desc2,
|
| 33 |
+
"Description 3": desc3,
|
| 34 |
+
})
|
| 35 |
+
|
|
|
|
|
|
|
|
|
|
| 36 |
return "Data saved successfully"
|
| 37 |
|
| 38 |
+
# Create the Gradio interface
|
| 39 |
iface = gr.Interface(
|
| 40 |
fn=describe_image,
|
| 41 |
inputs=[
|
| 42 |
gr.Image(type="pil", label="Upload an Image"),
|
| 43 |
+
gr.DatasetInput(type="gradio"),
|
| 44 |
"text",
|
| 45 |
"text",
|
| 46 |
"text"
|
|
|
|
| 56 |
)
|
| 57 |
)
|
| 58 |
|
| 59 |
+
# Launch the Gradio interface
|
| 60 |
+
iface.launch(share=True)
|