Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
| 9 |
|
| 10 |
model = SentimentModel()
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
allow_methods=["*"],
|
| 19 |
-
allow_headers=["*"],
|
| 20 |
)
|
| 21 |
|
| 22 |
-
|
| 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 |
|