GenAIDevTOProd commited on
Commit
19c66ed
·
verified ·
1 Parent(s): cb627cc

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """app.py
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/14li2A2e6uXyOUJztPqqlallXTtuGJTGl
8
+ """
9
+
10
+ from fastapi import FastAPI
11
+ from pydantic import BaseModel
12
+ from transformers import pipeline
13
+
14
+ # Init FastAPI
15
+ app = FastAPI(title="FastAPI Inference Template", version="1.0")
16
+
17
+ # Example model (can be swapped out easily)
18
+ model = pipeline("sentiment-analysis")
19
+
20
+ # Request schema
21
+ class InferenceRequest(BaseModel):
22
+ text: str
23
+
24
+ # Root check
25
+ @app.get("/")
26
+ def root():
27
+ return {"status": "ok", "message": "Inference API is live"}
28
+
29
+ # Predict endpoint
30
+ @app.post("/predict")
31
+ def predict(request: InferenceRequest):
32
+ result = model(request.text)
33
+ return {"input": request.text, "output": result}