FareehaAly commited on
Commit
49372bb
·
verified ·
1 Parent(s): 718e56f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -25
app.py CHANGED
@@ -1,35 +1,27 @@
1
- from fastapi import FastAPI
2
- from fastapi.middleware.cors import CORSMiddleware
3
- from pydantic import BaseModel
4
- from transformers import pipeline
5
  import gradio as gr
 
6
 
7
  print("Loading models...")
8
  quality_pipe = pipeline("text-classification", model="FareehaAly/fator-argument-quality", top_k=None)
9
  fallacy_pipe = pipeline("text-classification", model="FareehaAly/fator-fallacy-detector", top_k=None)
10
  print("Models loaded!")
11
 
12
- app = FastAPI()
13
- app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])
14
-
15
- class Input(BaseModel):
16
- text: str
17
 
18
- @app.post("/quality")
19
- def quality(inp: Input):
20
- return quality_pipe(inp.text[:512])
21
-
22
- @app.post("/fallacy")
23
- def fallacy(inp: Input):
24
- return fallacy_pipe(inp.text[:512])
25
-
26
- def q(text): return quality_pipe(text[:512])
27
- def f(text): return fallacy_pipe(text[:512])
28
 
29
  with gr.Blocks() as demo:
30
- gr.Markdown("## FATOR NLP API")
31
- t = gr.Textbox(label="Input text")
32
- gr.Button("Run Quality").click(q, t, gr.JSON(label="Quality result"))
33
- gr.Button("Run Fallacy").click(f, t, gr.JSON(label="Fallacy result"))
34
-
35
- app = gr.mount_gradio_app(app, demo, path="/")
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
  print("Loading models...")
5
  quality_pipe = pipeline("text-classification", model="FareehaAly/fator-argument-quality", top_k=None)
6
  fallacy_pipe = pipeline("text-classification", model="FareehaAly/fator-fallacy-detector", top_k=None)
7
  print("Models loaded!")
8
 
9
+ def predict_quality(text):
10
+ return quality_pipe(text[:512])
 
 
 
11
 
12
+ def predict_fallacy(text):
13
+ return fallacy_pipe(text[:512])
 
 
 
 
 
 
 
 
14
 
15
  with gr.Blocks() as demo:
16
+ gr.Markdown("## FATOR NLP API - Running")
17
+ with gr.Row():
18
+ txt = gr.Textbox(label="Input text", scale=4)
19
+ with gr.Row():
20
+ btn_q = gr.Button("Quality")
21
+ btn_f = gr.Button("Fallacy")
22
+ out_q = gr.JSON(label="Quality Result")
23
+ out_f = gr.JSON(label="Fallacy Result")
24
+ btn_q.click(predict_quality, inputs=txt, outputs=out_q, api_name="quality")
25
+ btn_f.click(predict_fallacy, inputs=txt, outputs=out_f, api_name="fallacy")
26
+
27
+ demo.launch(server_name="0.0.0.0", server_port=7860)