File size: 1,968 Bytes
78e61dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import gradio as gr
from transformers import pipeline

# βœ… Sentiment Analysis
sentiment_pipeline = pipeline("sentiment-analysis")

def analyze_sentiment(text):
    result = sentiment_pipeline(text)[0]
    return f"{result['label']} ({result['score']:.2f})"

# βœ… Toxic Comment Detection (uses a toxicity model from Hugging Face)
toxic_pipeline = pipeline("text-classification", model="unitary/toxic-bert")

def detect_toxic(text):
    result = toxic_pipeline(text)[0]
    return f"{result['label']} ({result['score']:.2f})"

# βœ… Image Captioning Model (BLIP)
image_captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")

def caption_image(image):
    result = image_captioner(image)[0]['generated_text']
    return result

# βœ… Speech-to-Text Model (whisper)
speech_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-tiny")

def speech_to_text(audio):
    result = speech_pipeline(audio)
    return result['text']

# 🟑 Placeholder for Style Transfer (optional upgrade later)
def style_transfer(image, style):
    return image  # Replace with real model later

# βœ… Gradio App Setup
with gr.Blocks() as demo:
    gr.Markdown("# πŸš€ ML Playground Dashboard")

    with gr.Tab("Sentiment Analyzer"):
        gr.Interface(fn=analyze_sentiment, inputs=gr.Textbox(), outputs=gr.Textbox())

    with gr.Tab("Toxic Comment Detector"):
        gr.Interface(fn=detect_toxic, inputs=gr.Textbox(), outputs=gr.Textbox())

    with gr.Tab("Image Caption Generator"):
        gr.Interface(fn=caption_image, inputs=gr.Image(type="pil"), outputs=gr.Textbox())

    with gr.Tab("Speech-to-Text"):
        gr.Interface(fn=speech_to_text, inputs=gr.Audio(type="filepath"), outputs=gr.Textbox())

    with gr.Tab("Art Style Transfer"):
        gr.Interface(
            fn=style_transfer,
            inputs=[gr.Image(), gr.Dropdown(["Van Gogh", "Monet", "Picasso"])],
            outputs=gr.Image()
        )

demo.launch()