ReviewGuard / app.py
Emirinth's picture
Deploy ReviewGuard
edfb6c0 verified
Raw History Blame Contribute Delete
2.04 kB
"""Start the ReviewGuard web app.
Run it locally with `python app.py`.
Add `--share` for a temporary public link to this computer.
The same file starts the app on Hugging Face Spaces.
"""
import argparse
import gradio as gr
from reviewguard import config
from reviewguard.analyzer import ReviewAnalyzer
from reviewguard.ui import about_tab, batch_tab, lab_tab, performance_tab, triage_tab
HEADER = """
# 🛡️ ReviewGuard
**AI triage for retail reviews.** Reads what the customer wrote, what they rated and what their
photo shows, then flags the orders that need action and routes them to the right team.
"""
def build_app() -> gr.Blocks:
"""Load the models and assemble every tab of the app.
Stops with a clear message if the models have not been trained yet.
"""
if not config.SENTIMENT_MODEL_DIR.exists():
raise SystemExit(
"Trained models not found in artifacts/models. "
"Run `python pipeline.py fetch-models` to download them, "
"or retrain with the README steps."
)
analyzer = ReviewAnalyzer()
with gr.Blocks(title="ReviewGuard") as app:
gr.Markdown(HEADER)
with gr.Tab("Review triage"):
triage_tab.build(analyzer)
with gr.Tab("Batch triage"):
batch_tab.build(analyzer)
with gr.Tab("Model lab"):
lab_tab.build(analyzer)
with gr.Tab("Model performance"):
performance_tab.build()
with gr.Tab("How it works"):
about_tab.build()
return app
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Start the ReviewGuard web app.")
parser.add_argument("--share", action="store_true", help="create a temporary public link")
args = parser.parse_args()
# The artifacts folder holds the example files and report figures the app displays.
build_app().launch(
theme=gr.themes.Soft(), share=args.share, allowed_paths=[str(config.ARTIFACTS_DIR)]
)