win2win commited on
Commit
8acfab4
·
verified ·
1 Parent(s): 5d51fd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -1,18 +1,20 @@
 
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
- # Load model with CPU (required for free Spaces)
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
- # Create Gradio interface
13
- gr.Interface(
14
- fn=predict,
15
- inputs="text",
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="/")