Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,100 +53,100 @@
|
|
| 53 |
|
| 54 |
|
| 55 |
################################################### Approach 2
|
| 56 |
-
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
|
| 73 |
-
#
|
| 74 |
-
#
|
| 75 |
-
|
| 76 |
-
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
################################################### Approach 3
|
| 86 |
-
import streamlit as st
|
| 87 |
-
from datasets import Dataset, load_dataset, concatenate_datasets
|
| 88 |
-
from st_img_pastebutton import paste
|
| 89 |
-
from io import BytesIO
|
| 90 |
-
import base64
|
| 91 |
|
| 92 |
-
from huggingface_hub import login, HfFolder
|
| 93 |
-
import os
|
| 94 |
|
| 95 |
-
# Set the token
|
| 96 |
-
token = os.getenv("HF_TOKEN") # Replace "YOUR_AUTHENTICATION_TOKEN" with your actual token
|
| 97 |
|
| 98 |
-
# Login using the token
|
| 99 |
|
| 100 |
-
login(token=token)
|
| 101 |
|
| 102 |
-
# Function to push feedback data to Hugging Face Hub dataset
|
| 103 |
-
def push_to_dataset(feedback, comments, image):
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
|
| 115 |
-
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
|
| 120 |
-
def main():
|
| 121 |
-
|
| 122 |
-
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
|
| 151 |
-
if __name__ == "__main__":
|
| 152 |
-
|
|
|
|
| 53 |
|
| 54 |
|
| 55 |
################################################### Approach 2
|
| 56 |
+
import streamlit as st
|
| 57 |
|
| 58 |
+
def collect_feedback():
|
| 59 |
+
st.title("Feedback Collection App")
|
| 60 |
|
| 61 |
+
# Display thumbs up/down buttons for feedback
|
| 62 |
+
feedback = st.radio("Was this helpful?", ('π', 'π'))
|
| 63 |
|
| 64 |
+
# Text input for comments
|
| 65 |
+
comments = st.text_area("Please provide any comments or suggestions:")
|
| 66 |
|
| 67 |
+
if st.button("Submit"):
|
| 68 |
+
if feedback == 'π':
|
| 69 |
+
st.success("Thank you for your positive feedback!")
|
| 70 |
+
elif feedback == 'π':
|
| 71 |
+
st.error("We're sorry to hear that. Please let us know how we can improve.")
|
| 72 |
|
| 73 |
+
# Do something with the feedback and comments (e.g., save to a database)
|
| 74 |
+
# For now, just print them
|
| 75 |
+
st.write("Feedback:", feedback)
|
| 76 |
+
st.write("Comments:", comments)
|
| 77 |
|
| 78 |
+
if __name__ == "__main__":
|
| 79 |
+
collect_feedback()
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
################################################### Approach 3
|
| 86 |
+
# import streamlit as st
|
| 87 |
+
# from datasets import Dataset, load_dataset, concatenate_datasets
|
| 88 |
+
# from st_img_pastebutton import paste
|
| 89 |
+
# from io import BytesIO
|
| 90 |
+
# import base64
|
| 91 |
|
| 92 |
+
# from huggingface_hub import login, HfFolder
|
| 93 |
+
# import os
|
| 94 |
|
| 95 |
+
# # Set the token
|
| 96 |
+
# token = os.getenv("HF_TOKEN") # Replace "YOUR_AUTHENTICATION_TOKEN" with your actual token
|
| 97 |
|
| 98 |
+
# # Login using the token
|
| 99 |
|
| 100 |
+
# login(token=token)
|
| 101 |
|
| 102 |
+
# # Function to push feedback data to Hugging Face Hub dataset
|
| 103 |
+
# def push_to_dataset(feedback, comments, image):
|
| 104 |
+
# # Load existing dataset or create a new one if it doesn't exist
|
| 105 |
+
# try:
|
| 106 |
+
# ds = load_dataset("YashB1/Feedbacks_vf", split="evaluation")
|
| 107 |
+
# except FileNotFoundError:
|
| 108 |
+
# # If dataset doesn't exist, create a new one
|
| 109 |
+
# ds = Dataset.from_dict({"feedback": [], "comments": [], "image": []})
|
| 110 |
|
| 111 |
+
# # Add new feedback to the dataset
|
| 112 |
+
# new_data = {"feedback": [feedback], "comments": [comments], "image": [image]} # Convert feedback and comments to lists
|
| 113 |
+
# new_data = Dataset.from_dict(new_data)
|
| 114 |
|
| 115 |
+
# ds = concatenate_datasets([ds, new_data])
|
| 116 |
|
| 117 |
+
# # Push the updated dataset to Hugging Face Hub
|
| 118 |
+
# ds.push_to_hub("YashB1/Feedbacks_vf", split="evaluation")
|
| 119 |
|
| 120 |
+
# def main():
|
| 121 |
+
# st.header("Feedback and Image Upload Example")
|
| 122 |
+
# st.write("Provide feedback using thumbs up or thumbs down, then upload an image, and add comments.")
|
| 123 |
|
| 124 |
+
# # Feedback section
|
| 125 |
+
# feedback = st.radio("Feedback:", options=["Thumbs Up π", "Thumbs Down π"])
|
| 126 |
|
| 127 |
+
# # Image upload section
|
| 128 |
+
# st.write("Click the button below to upload an image.")
|
| 129 |
+
# image_data = paste(key="image_clipboard", label="Upload Image")
|
| 130 |
+
# if image_data is not None:
|
| 131 |
+
# header, encoded = image_data.split(",", 1)
|
| 132 |
+
# binary_data = base64.b64decode(encoded)
|
| 133 |
+
# bytes_data = BytesIO(binary_data)
|
| 134 |
+
# st.image(bytes_data, caption="Uploaded Image", use_column_width=True)
|
| 135 |
+
# else:
|
| 136 |
+
# st.write("No image uploaded yet.")
|
| 137 |
|
| 138 |
+
# # Comments section
|
| 139 |
+
# comments = st.text_area("Comments:")
|
| 140 |
|
| 141 |
+
# # Button to submit feedback, image, and comments
|
| 142 |
+
# if st.button("Submit"):
|
| 143 |
+
# if feedback and comments.strip() and image_data:
|
| 144 |
+
# # Convert image_data to string
|
| 145 |
+
# image_data_str = str(image_data)
|
| 146 |
+
# push_to_dataset(feedback, comments, image_data_str)
|
| 147 |
+
# st.success("Feedback submitted successfully!")
|
| 148 |
+
# else:
|
| 149 |
+
# st.error("Please provide feedback, comments, and upload an image.")
|
| 150 |
|
| 151 |
+
# if __name__ == "__main__":
|
| 152 |
+
# main()
|