Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,6 +44,22 @@ def ask_rail_defect_question(question, model_name='ft:gpt-3.5-turbo-0125:persona
|
|
| 44 |
)
|
| 45 |
return response.choices[0].message['content']
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
def generate_variations(base_prompt, number_of_variations):
|
| 48 |
locations = ["on the left side", "on the right side", "at the top", "at the bottom", "in the center"]
|
| 49 |
sizes = ["small", "medium", "large", "tiny", "huge"]
|
|
@@ -106,17 +122,21 @@ with gr.Blocks() as app:
|
|
| 106 |
feedback_input = gr.Textbox(label="Enter your feedback", placeholder="Write your feedback here...")
|
| 107 |
like_button = gr.Button(value="π Like")
|
| 108 |
dislike_button = gr.Button(value="π Dislike")
|
| 109 |
-
feedback_result = gr.Textbox(label="System Response"
|
|
|
|
| 110 |
refresh_button = gr.Button("Refresh Page")
|
| 111 |
|
| 112 |
|
| 113 |
def handle_feedback(feedback, sentiment):
|
| 114 |
-
analysis =
|
| 115 |
if sentiment == "π Like":
|
| 116 |
return f"Thank you for your positive feedback! Your feedback: '{feedback}' was analyzed as: '{analysis}'. We are updating our system based on your feedback."
|
| 117 |
-
|
| 118 |
return f"We're sorry to hear that. Your feedback: '{feedback}' was analyzed as: '{analysis}'. We are updating our system based on your feedback."
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
| 120 |
like_button.click(lambda x: handle_feedback(x, "π Like"), inputs=feedback_input, outputs=feedback_result)
|
| 121 |
dislike_button.click(lambda x: handle_feedback(x, "π Dislike"), inputs=feedback_input, outputs=feedback_result)
|
| 122 |
refresh_button.click(lambda: gr.update(reload_browser=True))
|
|
|
|
| 44 |
)
|
| 45 |
return response.choices[0].message['content']
|
| 46 |
|
| 47 |
+
def ask_feedback(question, model_name='gpt-3.5-turbo'):
|
| 48 |
+
response = openai.ChatCompletion.create(
|
| 49 |
+
model=model_name,
|
| 50 |
+
messages=[
|
| 51 |
+
{
|
| 52 |
+
"role": "system",
|
| 53 |
+
"content": "The assistant is knowledgeable about user feedback and can analysis feedback and answer user-firndly way that they are updating the system message and LLM continuosly.",
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"role": "user",
|
| 57 |
+
"content": question,
|
| 58 |
+
}
|
| 59 |
+
],
|
| 60 |
+
)
|
| 61 |
+
return response.choices[0].message['content']
|
| 62 |
+
|
| 63 |
def generate_variations(base_prompt, number_of_variations):
|
| 64 |
locations = ["on the left side", "on the right side", "at the top", "at the bottom", "in the center"]
|
| 65 |
sizes = ["small", "medium", "large", "tiny", "huge"]
|
|
|
|
| 122 |
feedback_input = gr.Textbox(label="Enter your feedback", placeholder="Write your feedback here...")
|
| 123 |
like_button = gr.Button(value="π Like")
|
| 124 |
dislike_button = gr.Button(value="π Dislike")
|
| 125 |
+
feedback_result = gr.Textbox(label="System Response")
|
| 126 |
+
send_feedback_button = gr.Button("Send Feedback π")
|
| 127 |
refresh_button = gr.Button("Refresh Page")
|
| 128 |
|
| 129 |
|
| 130 |
def handle_feedback(feedback, sentiment):
|
| 131 |
+
analysis = ask_feedback(feedback)
|
| 132 |
if sentiment == "π Like":
|
| 133 |
return f"Thank you for your positive feedback! Your feedback: '{feedback}' was analyzed as: '{analysis}'. We are updating our system based on your feedback."
|
| 134 |
+
elif sentiment == "π Dislike":
|
| 135 |
return f"We're sorry to hear that. Your feedback: '{feedback}' was analyzed as: '{analysis}'. We are updating our system based on your feedback."
|
| 136 |
+
else:
|
| 137 |
+
return f"Your feedback: '{feedback}' was analyzed as: '{analysis}'. We are updating our system based on your feedback."
|
| 138 |
+
|
| 139 |
+
send_feedback_button.click(lambda x: handle_feedback(x, ""), inputs=feedback_input, outputs=feedback_result)
|
| 140 |
like_button.click(lambda x: handle_feedback(x, "π Like"), inputs=feedback_input, outputs=feedback_result)
|
| 141 |
dislike_button.click(lambda x: handle_feedback(x, "π Dislike"), inputs=feedback_input, outputs=feedback_result)
|
| 142 |
refresh_button.click(lambda: gr.update(reload_browser=True))
|