Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,8 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
import gradio as gr
|
| 3 |
-
import uvicorn
|
| 4 |
-
|
| 5 |
-
from transformers import pipeline
|
| 6 |
-
from gradio.components import Textbox
|
| 7 |
-
|
| 8 |
app = FastAPI()
|
| 9 |
-
|
| 10 |
-
# Load the sentiment analysis pipeline with DistilBERT
|
| 11 |
-
distilbert_pipeline = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 12 |
-
label_map = {"POSITIVE":"OTHER", "NEGATIVE":"SENSITIVE"}
|
| 13 |
-
|
| 14 |
-
input1 = Textbox(lines=2, placeholder="Type your text here...")
|
| 15 |
-
|
| 16 |
@app.get("/")
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
:param text: str, input text to analyze.
|
| 22 |
-
:return: str, predicted sentiment and confidence score.
|
| 23 |
-
"""
|
| 24 |
-
result = distilbert_pipeline(text)[0]
|
| 25 |
-
label = label_map[result['label']]
|
| 26 |
-
score = result['score']
|
| 27 |
-
return f"TAG: {label}, Confidence: {score:.2f}"
|
| 28 |
-
|
| 29 |
-
# Create a Gradio interface
|
| 30 |
-
text_input = gr.Interface(fn=predict_sentiment,
|
| 31 |
-
inputs=input1,
|
| 32 |
-
outputs="text",
|
| 33 |
-
title="Talk2Loop Sensitive statement tags",
|
| 34 |
-
description="This model predicts the sensitivity of the input text. Enter a sentence to see if it's sensitive or not.")
|
| 35 |
-
|
| 36 |
-
return text_input.launch(share=True, host="0.0.0.0", port=8000)
|
| 37 |
-
|
| 38 |
-
# Launch the interface
|
| 39 |
-
#app = gr.mount_gradio_app(app, text_input, path="/")
|
| 40 |
-
|
| 41 |
-
if __name__== "__main__":
|
| 42 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
| 43 |
-
|
| 44 |
-
# iface.launch(port=8000)
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
@app.get("/")
|
| 5 |
+
def read_main():
|
| 6 |
+
return {"message": "This is your main app"}
|
| 7 |
+
io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
|
| 8 |
+
app = gr.mount_gradio_app(app, io, path="/gradio")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|