|
|
|
|
|
|
|
|
|
|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
pipe = pipeline('sentiment-analysis') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def analyze_sentiment(text): |
|
|
if text.strip() == "": |
|
|
return {"error": "Please enter some text."} |
|
|
result = pipe(text) |
|
|
return result |
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("## Sentiment Analysis with Transformers") |
|
|
|
|
|
with gr.Row(): |
|
|
text_input = gr.Textbox( |
|
|
label="Enter your input:", |
|
|
placeholder="Type text here...", |
|
|
lines=4 |
|
|
) |
|
|
|
|
|
output = gr.JSON(label="Output") |
|
|
|
|
|
analyze_button = gr.Button("Analyze Sentiment") |
|
|
|
|
|
analyze_button.click( |
|
|
fn=analyze_sentiment, |
|
|
inputs=text_input, |
|
|
outputs=output |
|
|
) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|