Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ from datasets import Dataset
|
|
| 9 |
from huggingface_hub import HfApi, login
|
| 10 |
import time
|
| 11 |
|
|
|
|
| 12 |
from gradio_modal import Modal
|
| 13 |
import huggingface_hub
|
| 14 |
import datasets
|
|
@@ -131,7 +132,7 @@ def submit_research_feedback(conversation_history, satisfaction, feedback_text):
|
|
| 131 |
# Get token from environment variable
|
| 132 |
env_token = os.environ.get("HF_TOKEN")
|
| 133 |
|
| 134 |
-
# Use environment token
|
| 135 |
push_success = push_feedback_to_hub(env_token)
|
| 136 |
|
| 137 |
if push_success:
|
|
@@ -141,9 +142,8 @@ def submit_research_feedback(conversation_history, satisfaction, feedback_text):
|
|
| 141 |
|
| 142 |
return status_msg
|
| 143 |
|
| 144 |
-
#
|
| 145 |
with gr.Blocks() as demo:
|
| 146 |
-
|
| 147 |
with gr.Row():
|
| 148 |
with gr.Column(scale=3):
|
| 149 |
chatbot = gr.ChatInterface(
|
|
@@ -155,13 +155,6 @@ with gr.Blocks() as demo:
|
|
| 155 |
type="messages"
|
| 156 |
)
|
| 157 |
|
| 158 |
-
# Update conversation_state with each new message
|
| 159 |
-
chatbot.submit_btn.click(
|
| 160 |
-
lambda history: history,
|
| 161 |
-
inputs=[chatbot.chat_history],
|
| 162 |
-
outputs=[conversation_state]
|
| 163 |
-
)
|
| 164 |
-
|
| 165 |
with gr.Column(scale=1):
|
| 166 |
report_button = gr.Button("Share Feedback", variant="primary")
|
| 167 |
|
|
@@ -171,7 +164,6 @@ with gr.Blocks() as demo:
|
|
| 171 |
gr.Markdown("## Research Preview Feedback")
|
| 172 |
gr.Markdown("Thank you for testing our research model. Your feedback (positive or negative) helps us improve!")
|
| 173 |
|
| 174 |
-
# Remove HF token input as we're using environment variables
|
| 175 |
satisfaction = gr.Radio(
|
| 176 |
["Very satisfied", "Satisfied", "Neutral", "Unsatisfied", "Very unsatisfied"],
|
| 177 |
label="How would you rate your experience with this research model?",
|
|
@@ -187,17 +179,17 @@ with gr.Blocks() as demo:
|
|
| 187 |
submit_button = gr.Button("Submit Research Feedback", variant="primary")
|
| 188 |
response_text = gr.Textbox(label="Status", interactive=False)
|
| 189 |
|
| 190 |
-
# Connect the "
|
| 191 |
report_button.click(
|
| 192 |
lambda: Modal(visible=True),
|
| 193 |
None,
|
| 194 |
feedback_modal
|
| 195 |
)
|
| 196 |
|
| 197 |
-
# Connect the submit button to the submit_research_feedback function
|
| 198 |
submit_button.click(
|
| 199 |
-
submit_research_feedback,
|
| 200 |
-
inputs=[
|
| 201 |
outputs=response_text
|
| 202 |
)
|
| 203 |
|
|
|
|
| 9 |
from huggingface_hub import HfApi, login
|
| 10 |
import time
|
| 11 |
|
| 12 |
+
# Install required packages if not present
|
| 13 |
from gradio_modal import Modal
|
| 14 |
import huggingface_hub
|
| 15 |
import datasets
|
|
|
|
| 132 |
# Get token from environment variable
|
| 133 |
env_token = os.environ.get("HF_TOKEN")
|
| 134 |
|
| 135 |
+
# Use environment token
|
| 136 |
push_success = push_feedback_to_hub(env_token)
|
| 137 |
|
| 138 |
if push_success:
|
|
|
|
| 142 |
|
| 143 |
return status_msg
|
| 144 |
|
| 145 |
+
# Create the Gradio interface
|
| 146 |
with gr.Blocks() as demo:
|
|
|
|
| 147 |
with gr.Row():
|
| 148 |
with gr.Column(scale=3):
|
| 149 |
chatbot = gr.ChatInterface(
|
|
|
|
| 155 |
type="messages"
|
| 156 |
)
|
| 157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
with gr.Column(scale=1):
|
| 159 |
report_button = gr.Button("Share Feedback", variant="primary")
|
| 160 |
|
|
|
|
| 164 |
gr.Markdown("## Research Preview Feedback")
|
| 165 |
gr.Markdown("Thank you for testing our research model. Your feedback (positive or negative) helps us improve!")
|
| 166 |
|
|
|
|
| 167 |
satisfaction = gr.Radio(
|
| 168 |
["Very satisfied", "Satisfied", "Neutral", "Unsatisfied", "Very unsatisfied"],
|
| 169 |
label="How would you rate your experience with this research model?",
|
|
|
|
| 179 |
submit_button = gr.Button("Submit Research Feedback", variant="primary")
|
| 180 |
response_text = gr.Textbox(label="Status", interactive=False)
|
| 181 |
|
| 182 |
+
# Connect the "Share Feedback" button to show the modal
|
| 183 |
report_button.click(
|
| 184 |
lambda: Modal(visible=True),
|
| 185 |
None,
|
| 186 |
feedback_modal
|
| 187 |
)
|
| 188 |
|
| 189 |
+
# Connect the submit button to the submit_research_feedback function with the current chat history
|
| 190 |
submit_button.click(
|
| 191 |
+
lambda satisfaction, feedback_text: submit_research_feedback(chatbot.value, satisfaction, feedback_text),
|
| 192 |
+
inputs=[satisfaction, feedback_text],
|
| 193 |
outputs=response_text
|
| 194 |
)
|
| 195 |
|