Spaces:
Sleeping
Sleeping
Update app/feedback.py
Browse files- app/feedback.py +49 -0
app/feedback.py
CHANGED
|
@@ -137,4 +137,53 @@ def salvar_feedback(
|
|
| 137 |
note=note,
|
| 138 |
categoria_inferida=categoria_inferida,
|
| 139 |
feedback=feedback,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
|
|
|
| 137 |
note=note,
|
| 138 |
categoria_inferida=categoria_inferida,
|
| 139 |
feedback=feedback,
|
| 140 |
+
motivo=motivo,
|
| 141 |
+
score_final=score_final,
|
| 142 |
+
score_semantico=score_semantico,
|
| 143 |
+
bonus_lexical=bonus_lexical,
|
| 144 |
+
penalidade_feedback=penalidade_feedback,
|
| 145 |
+
user_message=user_message,
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
_append_feedback_csv(row)
|
| 149 |
+
saved_google_sheets = False
|
| 150 |
+
warning = None
|
| 151 |
+
|
| 152 |
+
try:
|
| 153 |
+
append_feedback_to_sheet(row)
|
| 154 |
+
saved_google_sheets = True
|
| 155 |
+
except GoogleAuthRequiredError:
|
| 156 |
+
warning = "Feedback salvo localmente, mas nao enviado ao Google Sheets. Acesse /auth/google para autorizar."
|
| 157 |
+
except Exception as exc:
|
| 158 |
+
warning = (
|
| 159 |
+
"Feedback salvo localmente, mas nao enviado ao Google Sheets. "
|
| 160 |
+
f"Erro de sincronizacao: {exc}"
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
if rating is not None and rating <= 2:
|
| 164 |
+
salvar_memoria_negativa(
|
| 165 |
+
query=query,
|
| 166 |
+
product_id=product_id,
|
| 167 |
+
product_name=product_name,
|
| 168 |
+
rating=rating,
|
| 169 |
+
motivo="rating_baixo",
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
if is_helpful is False:
|
| 173 |
+
salvar_memoria_negativa(
|
| 174 |
+
query=query,
|
| 175 |
+
product_id=product_id,
|
| 176 |
+
product_name=product_name,
|
| 177 |
+
rating=rating if rating is not None else "",
|
| 178 |
+
motivo="nao_foi_util",
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
response = {
|
| 182 |
+
"ok": True,
|
| 183 |
+
"saved_local": True,
|
| 184 |
+
"saved_google_sheets": saved_google_sheets,
|
| 185 |
+
}
|
| 186 |
+
if warning:
|
| 187 |
+
response["warning"] = warning
|
| 188 |
+
return response
|
| 189 |
|