YashB1 commited on
Commit
16c2d9d
Β·
verified Β·
1 Parent(s): 273df87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -21
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/Feedbacks", split="evaluation")
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
- # Save dataset back to Hugging Face Hub
115
- ds.push_to_hub("YashB1/Feedbacks", split="evaluation")
116
 
117
- def collect_feedback():
118
- st.title("Feedback Collection App")
119
 
120
- # Display thumbs up/down buttons for feedback
121
- feedback = st.radio("Was this helpful?", ('πŸ‘', 'πŸ‘Ž'))
 
122
 
123
- # Text input for comments
124
- comments = st.text_area("Please provide any comments or suggestions:")
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  if st.button("Submit"):
127
- if feedback == 'πŸ‘':
128
- st.success("Thank you for your positive feedback!")
129
- elif feedback == 'πŸ‘Ž':
130
- st.error("We're sorry to hear that. Please let us know how we can improve.")
131
-
132
- # Push feedback data to Hugging Face Hub dataset
133
- push_to_dataset(feedback, comments)
134
 
135
  if __name__ == "__main__":
136
- collect_feedback()
 
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()