################################################## Approach 1 import streamlit as st import json import os # Function to load existing feedback from a JSON file def load_feedback(filename): if os.path.exists(filename): with open(filename, 'r') as file: return json.load(file) else: return {'thumbs_up': 0, 'thumbs_down': 0, 'comments': []} # Function to save feedback to a JSON file def save_feedback(feedback, filename): with open(filename, 'w') as file: json.dump(feedback, file) # File to store feedback feedback_filename = "feedback.json" # Load existing feedback feedback = load_feedback(feedback_filename) # Display thumbs up/down buttons if st.button("👍 Thumbs Up"): feedback['thumbs_up'] += 1 save_feedback(feedback, feedback_filename) st.success("Thanks for your feedback!") if st.button("👎 Thumbs Down"): feedback['thumbs_down'] += 1 save_feedback(feedback, feedback_filename) st.error("We're sorry to hear that. Please reach out to us for further assistance.") # Comments section st.header("Comments") comment = st.text_area("Leave your comment here:") if st.button("Submit Comment"): feedback['comments'].append(comment) save_feedback(feedback, feedback_filename) st.success("Your comment has been submitted!") # Display current feedback st.write("Current Feedback:") st.write(f"👍 Thumbs Up: {feedback['thumbs_up']}") st.write(f"👎 Thumbs Down: {feedback['thumbs_down']}") st.write("Comments:") for c in feedback['comments']: st.write(c) ################################################### Approach 2 # import streamlit as st # def collect_feedback(): # st.title("Feedback Collection App") # # Display thumbs up/down buttons for feedback # feedback = st.radio("Was this helpful?", ('👍', '👎')) # # Text input for comments # comments = st.text_area("Please provide any comments or suggestions:") # if st.button("Submit"): # if feedback == '👍': # st.success("Thank you for your positive feedback!") # elif feedback == '👎': # st.error("We're sorry to hear that. Please let us know how we can improve.") # # Do something with the feedback and comments (e.g., save to a database) # # For now, just print them # st.write("Feedback:", feedback) # st.write("Comments:", comments) # if __name__ == "__main__": # collect_feedback() ################################################### Approach 3 # import streamlit as st # from datasets import Dataset, load_dataset, concatenate_datasets # from st_img_pastebutton import paste # from io import BytesIO # import base64 # from huggingface_hub import login, HfFolder # import os # # Set the token # token = os.getenv("HF_TOKEN") # Replace "YOUR_AUTHENTICATION_TOKEN" with your actual token # # Login using the token # login(token=token) # # Function to push feedback data to Hugging Face Hub dataset # def push_to_dataset(feedback, comments, image): # # Load existing dataset or create a new one if it doesn't exist # try: # ds = load_dataset("YashB1/Feedbacks_vf", split="evaluation") # except FileNotFoundError: # # If dataset doesn't exist, create a new one # ds = Dataset.from_dict({"feedback": [], "comments": [], "image": []}) # # Add new feedback to the dataset # new_data = {"feedback": [feedback], "comments": [comments], "image": [image]} # Convert feedback and comments to lists # new_data = Dataset.from_dict(new_data) # ds = concatenate_datasets([ds, new_data]) # # Push the updated dataset to Hugging Face Hub # ds.push_to_hub("YashB1/Feedbacks_vf", split="evaluation") # def main(): # st.header("Feedback and Image Upload Example") # st.write("Provide feedback using thumbs up or thumbs down, then upload an image, and add comments.") # # Feedback section # feedback = st.radio("Feedback:", options=["Thumbs Up 👍", "Thumbs Down 👎"]) # # Image upload section # st.write("Click the button below to upload an image.") # image_data = paste(key="image_clipboard", label="Upload Image") # if image_data is not None: # header, encoded = image_data.split(",", 1) # binary_data = base64.b64decode(encoded) # bytes_data = BytesIO(binary_data) # st.image(bytes_data, caption="Uploaded Image", use_column_width=True) # else: # st.write("No image uploaded yet.") # # Comments section # comments = st.text_area("Comments:") # # Button to submit feedback, image, and comments # if st.button("Submit"): # if feedback and comments.strip() and image_data: # # Convert image_data to string # image_data_str = str(image_data) # push_to_dataset(feedback, comments, image_data_str) # st.success("Feedback submitted successfully!") # else: # st.error("Please provide feedback, comments, and upload an image.") # if __name__ == "__main__": # main()