YashB1 commited on
Commit
70fe7c9
Β·
verified Β·
1 Parent(s): 2683b18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -71
app.py CHANGED
@@ -53,100 +53,100 @@
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()
 
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()