File size: 5,085 Bytes
0cd98a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e3fab7
 
caa9953
 
 
0cd98a2
caa9953
0cd98a2
 
caa9953
0cd98a2
 
caa9953
0cd98a2
 
caa9953
0cd98a2
 
 
 
 
caa9953
0cd98a2
 
 
 
caa9953
0cd98a2
 
caa9953
 
 
 
 
 
70fe7c9
 
 
 
 
caa9953
70fe7c9
 
93ecf67
70fe7c9
 
93ecf67
70fe7c9
93ecf67
70fe7c9
93ecf67
70fe7c9
 
 
 
 
 
 
 
caa9953
70fe7c9
 
 
caa9953
70fe7c9
4e3fab7
70fe7c9
 
4e3fab7
70fe7c9
 
 
4e3fab7
70fe7c9
 
f943288
70fe7c9
 
 
 
 
 
 
 
 
 
16c2d9d
70fe7c9
 
16c2d9d
70fe7c9
 
 
 
 
 
 
 
 
caa9953
70fe7c9
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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
152
153
################################################## 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()