Moncey10 commited on
Commit
52697ea
·
verified ·
1 Parent(s): 0899fc1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -25
app.py CHANGED
@@ -1,37 +1,23 @@
1
- from fastapi import FastAPI
2
- from pydantic import BaseModel
3
- from src.models.inference import SentimentModel
4
- from fastapi.middleware.cors import CORSMiddleware
5
  import nltk
6
  nltk.download('stopwords')
7
 
8
- app = FastAPI()
 
9
 
10
  model = SentimentModel()
11
 
 
 
 
12
 
13
- class TextInput(BaseModel):
14
- text: str
15
- app.add_middleware(
16
- CORSMiddleware,
17
- allow_origins=["*"], # later restrict this
18
- allow_methods=["*"],
19
- allow_headers=["*"],
20
  )
21
 
22
- @app.get("/")
23
- def home():
24
- return {"message": "Sentiment API running"}
25
-
26
-
27
- @app.post("/predict")
28
- def predict(input: TextInput):
29
- result = model.predict(input.text)
30
-
31
- return {
32
- "text": input.text,
33
- "sentiment": result
34
- }
35
 
36
 
37
 
 
 
 
 
 
1
  import nltk
2
  nltk.download('stopwords')
3
 
4
+ import gradio as gr
5
+ from src.models.inference import SentimentModel
6
 
7
  model = SentimentModel()
8
 
9
+ def predict(text):
10
+ result = model.predict(text)
11
+ return result
12
 
13
+ demo = gr.Interface(
14
+ fn=predict,
15
+ inputs=gr.Textbox(label="Enter Text"),
16
+ outputs=gr.Label(label="Sentiment"),
17
+ title="Sentiment Analysis",
 
 
18
  )
19
 
20
+ demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
 
23