Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
import io
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
-
from datasets import Dataset
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
|
| 10 |
-
# Function to
|
| 11 |
-
def
|
| 12 |
# Convert the Gradio PIL Image object to bytes
|
| 13 |
image_bytes = io.BytesIO()
|
| 14 |
|
|
@@ -16,12 +16,20 @@ def add_single_entry(image, desc1, desc2, desc3):
|
|
| 16 |
image.save(image_bytes, format="JPEG")
|
| 17 |
jpeg_data = image_bytes.getvalue()
|
| 18 |
|
| 19 |
-
data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
iface = gr.Interface(
|
| 24 |
-
fn=
|
| 25 |
inputs=[
|
| 26 |
gr.Image(type="pil", label="Upload an Image"),
|
| 27 |
"text",
|
|
@@ -39,8 +47,4 @@ iface = gr.Interface(
|
|
| 39 |
)
|
| 40 |
)
|
| 41 |
|
| 42 |
-
iface.launch(share=True)
|
| 43 |
-
|
| 44 |
-
# Save the dataset to a file on your local file system
|
| 45 |
-
dataset = Dataset.from_pandas(data)
|
| 46 |
-
dataset.save_to_disk("bestroi/Images")
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
import io
|
| 4 |
+
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 |
|
|
|
|
| 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",
|
|
|
|
| 47 |
)
|
| 48 |
)
|
| 49 |
|
| 50 |
+
iface.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|