Spaces:
Sleeping
Sleeping
GeorgeSherif
commited on
Commit
·
448a3a6
1
Parent(s):
72fc143
updates
Browse files- .gradio/certificate.pem +31 -0
- app.py +12 -27
.gradio/certificate.pem
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN CERTIFICATE-----
|
| 2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
| 3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
| 4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
| 5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
| 6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
| 7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
| 8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
| 9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
| 10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
| 11 |
+
T8KOEUt+zwvo/7V3L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3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
|
| 26 |
+
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
| 27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
| 28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
| 29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
| 30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
| 31 |
+
-----END CERTIFICATE-----
|
app.py
CHANGED
|
@@ -2,8 +2,10 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
import threading
|
| 4 |
import random
|
| 5 |
-
from datasets import load_dataset, Dataset, Features, Value
|
| 6 |
from huggingface_hub import login
|
|
|
|
|
|
|
| 7 |
token = os.getenv("HUGGINGFACE_TOKEN")
|
| 8 |
if token:
|
| 9 |
login(token=token)
|
|
@@ -13,8 +15,8 @@ dataset_name = "GeorgeIbrahim/EGYCOCO" # Replace with your dataset name
|
|
| 13 |
|
| 14 |
# Load or create the dataset
|
| 15 |
try:
|
| 16 |
-
dataset = load_dataset(dataset_name)
|
| 17 |
-
print(dataset)
|
| 18 |
except Exception as e:
|
| 19 |
# Create an empty dataset if it doesn't exist
|
| 20 |
features = Features({
|
|
@@ -32,7 +34,7 @@ current_image = None
|
|
| 32 |
# Function to get a random image that hasn’t been annotated or skipped
|
| 33 |
def get_next_image():
|
| 34 |
with lock:
|
| 35 |
-
available_images = [img for img in image_files]
|
| 36 |
if available_images:
|
| 37 |
return os.path.join(image_folder, random.choice(available_images))
|
| 38 |
return None
|
|
@@ -50,13 +52,14 @@ def save_annotation(caption):
|
|
| 50 |
if caption.strip().lower() == "skip":
|
| 51 |
caption = "skipped"
|
| 52 |
|
| 53 |
-
# Add the new annotation to the dataset
|
| 54 |
-
new_data = {"image_id": image_id, "caption": caption}
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
# Save updated dataset to Hugging Face
|
| 58 |
dataset.push_to_hub(dataset_name)
|
| 59 |
-
print("
|
| 60 |
|
| 61 |
# Fetch the next image
|
| 62 |
current_image = get_next_image()
|
|
@@ -67,25 +70,7 @@ def save_annotation(caption):
|
|
| 67 |
|
| 68 |
# Function to skip the current image
|
| 69 |
def skip_image():
|
| 70 |
-
|
| 71 |
-
if current_image is None:
|
| 72 |
-
return gr.update(visible=False), gr.update(value="All images have been annotated!")
|
| 73 |
-
|
| 74 |
-
with lock:
|
| 75 |
-
image_id = os.path.basename(current_image)
|
| 76 |
-
# Record "skipped" caption directly here
|
| 77 |
-
new_data = {"image_id": image_id, "caption": "skipped"}
|
| 78 |
-
dataset.add_item(new_data) # Update the dataset variable
|
| 79 |
-
|
| 80 |
-
# Save updated dataset to Hugging Face
|
| 81 |
-
dataset.push_to_hub(dataset_name)
|
| 82 |
-
|
| 83 |
-
# Fetch the next image
|
| 84 |
-
current_image = get_next_image()
|
| 85 |
-
if current_image:
|
| 86 |
-
return gr.update(value=current_image), gr.update(value="")
|
| 87 |
-
else:
|
| 88 |
-
return gr.update(visible=False), gr.update(value="All images have been annotated!")
|
| 89 |
|
| 90 |
# Function to initialize the interface
|
| 91 |
def initialize_interface():
|
|
|
|
| 2 |
import os
|
| 3 |
import threading
|
| 4 |
import random
|
| 5 |
+
from datasets import load_dataset, Dataset, Features, Value, concatenate_datasets
|
| 6 |
from huggingface_hub import login
|
| 7 |
+
|
| 8 |
+
# Authenticate with Hugging Face
|
| 9 |
token = os.getenv("HUGGINGFACE_TOKEN")
|
| 10 |
if token:
|
| 11 |
login(token=token)
|
|
|
|
| 15 |
|
| 16 |
# Load or create the dataset
|
| 17 |
try:
|
| 18 |
+
dataset = load_dataset(dataset_name, split="train")
|
| 19 |
+
print("Loaded existing dataset:", dataset)
|
| 20 |
except Exception as e:
|
| 21 |
# Create an empty dataset if it doesn't exist
|
| 22 |
features = Features({
|
|
|
|
| 34 |
# Function to get a random image that hasn’t been annotated or skipped
|
| 35 |
def get_next_image():
|
| 36 |
with lock:
|
| 37 |
+
available_images = [img for img in image_files if img not in dataset["image_id"]]
|
| 38 |
if available_images:
|
| 39 |
return os.path.join(image_folder, random.choice(available_images))
|
| 40 |
return None
|
|
|
|
| 52 |
if caption.strip().lower() == "skip":
|
| 53 |
caption = "skipped"
|
| 54 |
|
| 55 |
+
# Add the new annotation as a new row to the dataset
|
| 56 |
+
new_data = Dataset.from_dict({"image_id": [image_id], "caption": [caption]})
|
| 57 |
+
global dataset
|
| 58 |
+
dataset = concatenate_datasets([dataset, new_data])
|
| 59 |
|
| 60 |
# Save updated dataset to Hugging Face
|
| 61 |
dataset.push_to_hub(dataset_name)
|
| 62 |
+
print("Pushed updated dataset")
|
| 63 |
|
| 64 |
# Fetch the next image
|
| 65 |
current_image = get_next_image()
|
|
|
|
| 70 |
|
| 71 |
# Function to skip the current image
|
| 72 |
def skip_image():
|
| 73 |
+
return save_annotation("skip")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
# Function to initialize the interface
|
| 76 |
def initialize_interface():
|