CRYPTONEWS34's picture
Fix: remove duplicate demo.launch and use only Blocks UI
d89600d
import gradio as gr
from PIL import Image
from transformers import pipeline
# Initialize sentiment pipeline from transformers
sentiment_analyzer = pipeline("sentiment-analysis")
def analyze_sentiment(text):
result = sentiment_analyzer(text)
return result[0]['label'], result[0]['score']
def process_image(image):
# Example: Convert to grayscale (just a demo)
gray_image = image.convert("L")
return gray_image
with gr.Blocks() as demo:
gr.Markdown("## Crypto News API with Image and Sentiment Analysis")
with gr.Tab("Sentiment Analysis"):
text_input = gr.Textbox(label="Enter Text")
sentiment_output = gr.Label()
sentiment_score = gr.Textbox(label="Confidence Score")
text_input.submit(analyze_sentiment, inputs=text_input, outputs=[sentiment_output, sentiment_score])
with gr.Tab("Image Processing"):
image_input = gr.Image(type="pil")
image_output = gr.Image()
image_input.change(process_image, inputs=image_input, outputs=image_output)
demo.launch()