Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
class Input(BaseModel):
|
| 16 |
-
text: str
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 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 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|