Spaces:
Sleeping
Sleeping
Commit ·
20c0231
1
Parent(s): 58293de
Hide empty download outputs
Browse files
app.py
CHANGED
|
@@ -278,6 +278,10 @@ def _write_csv_download(name: str, headers: List[str], rows):
|
|
| 278 |
return str(path)
|
| 279 |
|
| 280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
def _normalize_table_rows(rows) -> List[List[Any]]:
|
| 282 |
if rows is None:
|
| 283 |
return []
|
|
@@ -751,11 +755,11 @@ def merchant_score_filter(aspect: str, prediction: str, category: str) -> List[L
|
|
| 751 |
|
| 752 |
|
| 753 |
def export_merchant_scores(rows):
|
| 754 |
-
return _write_csv_download(
|
| 755 |
"merchant_product_scores.csv",
|
| 756 |
["Product", "Category", "Metric", "Prediction", "Confidence", "Price", "Rating"],
|
| 757 |
rows,
|
| 758 |
-
)
|
| 759 |
|
| 760 |
|
| 761 |
def negative_product_spotlight(limit: int = 6) -> str:
|
|
@@ -881,11 +885,11 @@ def import_new_product_payload(file_obj):
|
|
| 881 |
|
| 882 |
|
| 883 |
def export_risk_rows(rows):
|
| 884 |
-
return _write_csv_download(
|
| 885 |
"new_product_metadata_risk.csv",
|
| 886 |
["Aspect", "Risk Level", "Model Signal", "Confidence", "Reason"],
|
| 887 |
rows,
|
| 888 |
-
)
|
| 889 |
|
| 890 |
|
| 891 |
def _read_uploaded_records(file_obj) -> List[Dict[str, Any]]:
|
|
@@ -913,11 +917,11 @@ def download_new_product_template():
|
|
| 913 |
35,
|
| 914 |
"All",
|
| 915 |
]]
|
| 916 |
-
return _write_csv_download(
|
| 917 |
"new_product_metadata_template.csv",
|
| 918 |
["features", "category", "price", "average_rating", "rating_number", "focus_aspect"],
|
| 919 |
rows,
|
| 920 |
-
)
|
| 921 |
|
| 922 |
|
| 923 |
def batch_screen_new_products(file_obj) -> Tuple[str, List[List[Any]]]:
|
|
@@ -976,11 +980,11 @@ def import_external_review_payload(file_obj):
|
|
| 976 |
|
| 977 |
|
| 978 |
def export_external_rows(rows):
|
| 979 |
-
return _write_csv_download(
|
| 980 |
"external_review_prediction.csv",
|
| 981 |
["Aspect", "Prediction", "Confidence", "Key review evidence"],
|
| 982 |
rows,
|
| 983 |
-
)
|
| 984 |
|
| 985 |
|
| 986 |
def download_external_review_template():
|
|
@@ -993,11 +997,11 @@ def download_external_review_template():
|
|
| 993 |
312,
|
| 994 |
"All",
|
| 995 |
]]
|
| 996 |
-
return _write_csv_download(
|
| 997 |
"external_review_template.csv",
|
| 998 |
["review", "features", "category", "price", "average_rating", "rating_number", "highlight_aspect"],
|
| 999 |
rows,
|
| 1000 |
-
)
|
| 1001 |
|
| 1002 |
|
| 1003 |
def batch_external_review_predict(file_obj) -> Tuple[str, str, List[List[Any]]]:
|
|
@@ -1167,7 +1171,7 @@ def build_app() -> gr.Blocks:
|
|
| 1167 |
with gr.Row():
|
| 1168 |
refresh_scores = gr.Button("Apply Score Filter", variant="primary")
|
| 1169 |
export_scores = gr.Button("Export Score List")
|
| 1170 |
-
merchant_scores_file = gr.File(label="Downloaded score CSV", interactive=False)
|
| 1171 |
with gr.Accordion("New Product Metadata Risk Screening", open=False):
|
| 1172 |
risk_mode = gr.Radio(["Single product analysis", "Batch import analysis"], value="Single product analysis", label="Analysis mode")
|
| 1173 |
with gr.Row():
|
|
@@ -1187,12 +1191,12 @@ def build_app() -> gr.Blocks:
|
|
| 1187 |
with gr.Row():
|
| 1188 |
new_template = gr.Button("Download Import Template")
|
| 1189 |
batch_screen_btn = gr.Button("Batch Analyze Metadata", variant="primary")
|
| 1190 |
-
new_template_file = gr.File(label="Template CSV", interactive=False)
|
| 1191 |
with gr.Column(scale=1):
|
| 1192 |
risk_summary = gr.HTML()
|
| 1193 |
risk_table = gr.Dataframe(headers=["Aspect", "Risk Level", "Model Signal", "Confidence", "Reason"], value=[["Click Predict Metadata Risk", "", "", 0.0, ""]], datatype=["str", "str", "str", "number", "str"], interactive=False)
|
| 1194 |
export_risk = gr.Button("Export Risk Result")
|
| 1195 |
-
risk_file = gr.File(label="Downloaded risk CSV", interactive=False)
|
| 1196 |
with gr.Accordion("External Review Prediction", open=False):
|
| 1197 |
ext_mode = gr.Radio(["Single product analysis", "Batch import analysis"], value="Single product analysis", label="Analysis mode")
|
| 1198 |
with gr.Row():
|
|
@@ -1214,13 +1218,13 @@ def build_app() -> gr.Blocks:
|
|
| 1214 |
with gr.Row():
|
| 1215 |
ext_template = gr.Button("Download Import Template")
|
| 1216 |
batch_external_btn = gr.Button("Batch Analyze Reviews", variant="primary")
|
| 1217 |
-
ext_template_file = gr.File(label="Template CSV", interactive=False)
|
| 1218 |
with gr.Column(scale=1):
|
| 1219 |
ext_overall = gr.HTML()
|
| 1220 |
ext_aspects = gr.HTML()
|
| 1221 |
ext_table = gr.Dataframe(headers=["Aspect", "Prediction", "Confidence", "Key review evidence"], value=[["Click Analyze External Review", "", 0.0, ""]], datatype=["str", "str", "number", "str"], interactive=False)
|
| 1222 |
export_ext = gr.Button("Export Review Result")
|
| 1223 |
-
ext_file = gr.File(label="Downloaded review CSV", interactive=False)
|
| 1224 |
refresh_scores.click(merchant_score_filter, [merchant_metric, merchant_prediction, merchant_category], merchant_scores)
|
| 1225 |
export_scores.click(export_merchant_scores, merchant_scores, merchant_scores_file)
|
| 1226 |
merchant_metric.change(merchant_score_filter, [merchant_metric, merchant_prediction, merchant_category], merchant_scores)
|
|
|
|
| 278 |
return str(path)
|
| 279 |
|
| 280 |
|
| 281 |
+
def _download_update(path: str):
|
| 282 |
+
return gr.update(value=path, visible=True)
|
| 283 |
+
|
| 284 |
+
|
| 285 |
def _normalize_table_rows(rows) -> List[List[Any]]:
|
| 286 |
if rows is None:
|
| 287 |
return []
|
|
|
|
| 755 |
|
| 756 |
|
| 757 |
def export_merchant_scores(rows):
|
| 758 |
+
return _download_update(_write_csv_download(
|
| 759 |
"merchant_product_scores.csv",
|
| 760 |
["Product", "Category", "Metric", "Prediction", "Confidence", "Price", "Rating"],
|
| 761 |
rows,
|
| 762 |
+
))
|
| 763 |
|
| 764 |
|
| 765 |
def negative_product_spotlight(limit: int = 6) -> str:
|
|
|
|
| 885 |
|
| 886 |
|
| 887 |
def export_risk_rows(rows):
|
| 888 |
+
return _download_update(_write_csv_download(
|
| 889 |
"new_product_metadata_risk.csv",
|
| 890 |
["Aspect", "Risk Level", "Model Signal", "Confidence", "Reason"],
|
| 891 |
rows,
|
| 892 |
+
))
|
| 893 |
|
| 894 |
|
| 895 |
def _read_uploaded_records(file_obj) -> List[Dict[str, Any]]:
|
|
|
|
| 917 |
35,
|
| 918 |
"All",
|
| 919 |
]]
|
| 920 |
+
return _download_update(_write_csv_download(
|
| 921 |
"new_product_metadata_template.csv",
|
| 922 |
["features", "category", "price", "average_rating", "rating_number", "focus_aspect"],
|
| 923 |
rows,
|
| 924 |
+
))
|
| 925 |
|
| 926 |
|
| 927 |
def batch_screen_new_products(file_obj) -> Tuple[str, List[List[Any]]]:
|
|
|
|
| 980 |
|
| 981 |
|
| 982 |
def export_external_rows(rows):
|
| 983 |
+
return _download_update(_write_csv_download(
|
| 984 |
"external_review_prediction.csv",
|
| 985 |
["Aspect", "Prediction", "Confidence", "Key review evidence"],
|
| 986 |
rows,
|
| 987 |
+
))
|
| 988 |
|
| 989 |
|
| 990 |
def download_external_review_template():
|
|
|
|
| 997 |
312,
|
| 998 |
"All",
|
| 999 |
]]
|
| 1000 |
+
return _download_update(_write_csv_download(
|
| 1001 |
"external_review_template.csv",
|
| 1002 |
["review", "features", "category", "price", "average_rating", "rating_number", "highlight_aspect"],
|
| 1003 |
rows,
|
| 1004 |
+
))
|
| 1005 |
|
| 1006 |
|
| 1007 |
def batch_external_review_predict(file_obj) -> Tuple[str, str, List[List[Any]]]:
|
|
|
|
| 1171 |
with gr.Row():
|
| 1172 |
refresh_scores = gr.Button("Apply Score Filter", variant="primary")
|
| 1173 |
export_scores = gr.Button("Export Score List")
|
| 1174 |
+
merchant_scores_file = gr.File(label="Downloaded score CSV", interactive=False, visible=False)
|
| 1175 |
with gr.Accordion("New Product Metadata Risk Screening", open=False):
|
| 1176 |
risk_mode = gr.Radio(["Single product analysis", "Batch import analysis"], value="Single product analysis", label="Analysis mode")
|
| 1177 |
with gr.Row():
|
|
|
|
| 1191 |
with gr.Row():
|
| 1192 |
new_template = gr.Button("Download Import Template")
|
| 1193 |
batch_screen_btn = gr.Button("Batch Analyze Metadata", variant="primary")
|
| 1194 |
+
new_template_file = gr.File(label="Template CSV", interactive=False, visible=False)
|
| 1195 |
with gr.Column(scale=1):
|
| 1196 |
risk_summary = gr.HTML()
|
| 1197 |
risk_table = gr.Dataframe(headers=["Aspect", "Risk Level", "Model Signal", "Confidence", "Reason"], value=[["Click Predict Metadata Risk", "", "", 0.0, ""]], datatype=["str", "str", "str", "number", "str"], interactive=False)
|
| 1198 |
export_risk = gr.Button("Export Risk Result")
|
| 1199 |
+
risk_file = gr.File(label="Downloaded risk CSV", interactive=False, visible=False)
|
| 1200 |
with gr.Accordion("External Review Prediction", open=False):
|
| 1201 |
ext_mode = gr.Radio(["Single product analysis", "Batch import analysis"], value="Single product analysis", label="Analysis mode")
|
| 1202 |
with gr.Row():
|
|
|
|
| 1218 |
with gr.Row():
|
| 1219 |
ext_template = gr.Button("Download Import Template")
|
| 1220 |
batch_external_btn = gr.Button("Batch Analyze Reviews", variant="primary")
|
| 1221 |
+
ext_template_file = gr.File(label="Template CSV", interactive=False, visible=False)
|
| 1222 |
with gr.Column(scale=1):
|
| 1223 |
ext_overall = gr.HTML()
|
| 1224 |
ext_aspects = gr.HTML()
|
| 1225 |
ext_table = gr.Dataframe(headers=["Aspect", "Prediction", "Confidence", "Key review evidence"], value=[["Click Analyze External Review", "", 0.0, ""]], datatype=["str", "str", "number", "str"], interactive=False)
|
| 1226 |
export_ext = gr.Button("Export Review Result")
|
| 1227 |
+
ext_file = gr.File(label="Downloaded review CSV", interactive=False, visible=False)
|
| 1228 |
refresh_scores.click(merchant_score_filter, [merchant_metric, merchant_prediction, merchant_category], merchant_scores)
|
| 1229 |
export_scores.click(export_merchant_scores, merchant_scores, merchant_scores_file)
|
| 1230 |
merchant_metric.change(merchant_score_filter, [merchant_metric, merchant_prediction, merchant_category], merchant_scores)
|