revaza commited on
Commit
423a505
·
verified ·
1 Parent(s): 14a8e57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -58,18 +58,19 @@ def api_predict(text):
58
  words = get_hate_words(text)
59
  return {"hate_words": words}
60
 
61
- # UI setup
62
- with gr.Blocks() as demo:
63
  input_text = gr.Textbox(label="Enter Georgian text")
64
  output_json = gr.JSON(label="Detected Hate Words")
65
  submit_btn = gr.Button("Predict")
66
-
67
  submit_btn.click(fn=api_predict, inputs=input_text, outputs=output_json)
68
 
69
- # FastAPI app for exposing /predict
70
  app = FastAPI()
71
- app = mount_gradio_app(app, demo, path="/") # UI at /
72
 
73
- # Extra endpoint at /predict (external API POST)
74
- api_iface = gr.Interface(fn=api_predict, inputs=gr.Textbox(), outputs="json")
75
- app = mount_gradio_app(app, api_iface, path="/predict") # POST at /predict
 
 
 
 
58
  words = get_hate_words(text)
59
  return {"hate_words": words}
60
 
61
+ # Create the main Gradio UI
62
+ with gr.Blocks() as gradio_ui:
63
  input_text = gr.Textbox(label="Enter Georgian text")
64
  output_json = gr.JSON(label="Detected Hate Words")
65
  submit_btn = gr.Button("Predict")
 
66
  submit_btn.click(fn=api_predict, inputs=input_text, outputs=output_json)
67
 
68
+ # Create FastAPI app
69
  app = FastAPI()
 
70
 
71
+ # Mount Gradio UI at `/`
72
+ app = mount_gradio_app(app, gradio_ui, path="/")
73
+
74
+ # Mount Gradio API interface at `/predict`
75
+ api_interface = gr.Interface(fn=api_predict, inputs=gr.Textbox(), outputs="json")
76
+ app = mount_gradio_app(app, api_interface, path="/predict")