File size: 1,035 Bytes
63b8f61 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# Install dependencies if not already installed
# !pip install gradio transformers
import gradio as gr
from transformers import pipeline
# Load sentiment analysis pipeline
pipe = pipeline('sentiment-analysis')
# For financial sentiment analysis you can use:
# pipe = pipeline("text-classification", model="ProsusAI/finbert")
# Define function
def analyze_sentiment(text):
if text.strip() == "":
return {"error": "Please enter some text."}
result = pipe(text)
return result
# Gradio Interface
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
)
# Launch app
if __name__ == "__main__":
demo.launch()
|