Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
|
| 5 |
-
model = pipeline("text-classification",
|
| 6 |
-
model="win2win/3-epochs-classifier-ver2",
|
| 7 |
-
device="cpu")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def predict(text):
|
| 10 |
return model(text)
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
outputs="json",
|
| 17 |
-
title="Text Classifier"
|
| 18 |
-
).launch()
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
from transformers import pipeline
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
model = pipeline("text-classification", model="win2win/3-epochs-classifier-ver2")
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# Custom endpoint
|
| 9 |
+
@app.post("/predict")
|
| 10 |
+
async def api_predict(text: str):
|
| 11 |
+
return model(text)
|
| 12 |
+
|
| 13 |
+
# Gradio interface
|
| 14 |
def predict(text):
|
| 15 |
return model(text)
|
| 16 |
|
| 17 |
+
io = gr.Interface(fn=predict, inputs="text", outputs="json")
|
| 18 |
+
|
| 19 |
+
# Mount both endpoints
|
| 20 |
+
app = gr.mount_gradio_app(app, io, path="/")
|
|
|
|
|
|
|
|
|