Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -98,39 +98,53 @@ token = os.getenv("HF_TOKEN") # Replace "YOUR_AUTHENTICATION_TOKEN" with your a
|
|
| 98 |
login(token=token)
|
| 99 |
|
| 100 |
# Function to push feedback data to Hugging Face Hub dataset
|
| 101 |
-
def push_to_dataset(feedback, comments):
|
| 102 |
# Load existing dataset or create a new one if it doesn't exist
|
| 103 |
try:
|
| 104 |
-
ds = load_dataset("YashB1/
|
| 105 |
except FileNotFoundError:
|
| 106 |
# If dataset doesn't exist, create a new one
|
| 107 |
-
ds = Dataset.from_dict({"feedback": [], "comments": []})
|
| 108 |
|
| 109 |
# Add new feedback to the dataset
|
| 110 |
-
new_data = {"feedback": [feedback], "comments": [comments]} # Convert feedback and comments to lists
|
| 111 |
new_data = Dataset.from_dict(new_data)
|
| 112 |
-
ds = concatenate_datasets([ds,new_data])
|
| 113 |
|
| 114 |
-
|
| 115 |
-
ds.push_to_hub("YashB1/Feedbacks", split="evaluation")
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
|
|
|
| 122 |
|
| 123 |
-
#
|
| 124 |
-
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
if st.button("Submit"):
|
| 127 |
-
if feedback
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
| 136 |
-
|
|
|
|
| 98 |
login(token=token)
|
| 99 |
|
| 100 |
# Function to push feedback data to Hugging Face Hub dataset
|
| 101 |
+
def push_to_dataset(feedback, comments, image):
|
| 102 |
# Load existing dataset or create a new one if it doesn't exist
|
| 103 |
try:
|
| 104 |
+
ds = load_dataset("YashB1/Feedbacks_Version2", split="evaluation")
|
| 105 |
except FileNotFoundError:
|
| 106 |
# If dataset doesn't exist, create a new one
|
| 107 |
+
ds = Dataset.from_dict({"feedback": [], "comments": [], "image": []})
|
| 108 |
|
| 109 |
# Add new feedback to the dataset
|
| 110 |
+
new_data = {"feedback": [feedback], "comments": [comments], "image": [image]} # Convert feedback and comments to lists
|
| 111 |
new_data = Dataset.from_dict(new_data)
|
|
|
|
| 112 |
|
| 113 |
+
ds = concatenate_datasets([ds, new_data])
|
|
|
|
| 114 |
|
| 115 |
+
# Push the updated dataset to Hugging Face Hub
|
| 116 |
+
ds.push_to_hub("YashB1/Feedbacks_Version2", split="evaluation")
|
| 117 |
|
| 118 |
+
def main():
|
| 119 |
+
st.header("Feedback and Image Upload Example")
|
| 120 |
+
st.write("Provide feedback using thumbs up or thumbs down, then upload an image, and add comments.")
|
| 121 |
|
| 122 |
+
# Feedback section
|
| 123 |
+
feedback = st.radio("Feedback:", options=["Thumbs Up π", "Thumbs Down π"])
|
| 124 |
|
| 125 |
+
# Image upload section
|
| 126 |
+
st.write("Click the button below to upload an image.")
|
| 127 |
+
image_data = paste(key="image_clipboard", label="Upload Image")
|
| 128 |
+
if image_data is not None:
|
| 129 |
+
header, encoded = image_data.split(",", 1)
|
| 130 |
+
binary_data = base64.b64decode(encoded)
|
| 131 |
+
bytes_data = BytesIO(binary_data)
|
| 132 |
+
st.image(bytes_data, caption="Uploaded Image", use_column_width=True)
|
| 133 |
+
else:
|
| 134 |
+
st.write("No image uploaded yet.")
|
| 135 |
+
|
| 136 |
+
# Comments section
|
| 137 |
+
comments = st.text_area("Comments:")
|
| 138 |
+
|
| 139 |
+
# Button to submit feedback, image, and comments
|
| 140 |
if st.button("Submit"):
|
| 141 |
+
if feedback and comments.strip() and image_data:
|
| 142 |
+
# Convert image_data to string
|
| 143 |
+
image_data_str = str(image_data)
|
| 144 |
+
push_to_dataset(feedback, comments, image_data_str)
|
| 145 |
+
st.success("Feedback submitted successfully!")
|
| 146 |
+
else:
|
| 147 |
+
st.error("Please provide feedback, comments, and upload an image.")
|
| 148 |
|
| 149 |
if __name__ == "__main__":
|
| 150 |
+
main()
|