ABDULLAH BILAL commited on
Commit
78e61dd
Β·
verified Β·
1 Parent(s): 6f38418

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -1
app.py CHANGED
@@ -1 +1,59 @@
1
- # Paste your final gradio code here (the one I just sent you)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # βœ… Sentiment Analysis
5
+ sentiment_pipeline = pipeline("sentiment-analysis")
6
+
7
+ def analyze_sentiment(text):
8
+ result = sentiment_pipeline(text)[0]
9
+ return f"{result['label']} ({result['score']:.2f})"
10
+
11
+ # βœ… Toxic Comment Detection (uses a toxicity model from Hugging Face)
12
+ toxic_pipeline = pipeline("text-classification", model="unitary/toxic-bert")
13
+
14
+ def detect_toxic(text):
15
+ result = toxic_pipeline(text)[0]
16
+ return f"{result['label']} ({result['score']:.2f})"
17
+
18
+ # βœ… Image Captioning Model (BLIP)
19
+ image_captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
20
+
21
+ def caption_image(image):
22
+ result = image_captioner(image)[0]['generated_text']
23
+ return result
24
+
25
+ # βœ… Speech-to-Text Model (whisper)
26
+ speech_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-tiny")
27
+
28
+ def speech_to_text(audio):
29
+ result = speech_pipeline(audio)
30
+ return result['text']
31
+
32
+ # 🟑 Placeholder for Style Transfer (optional upgrade later)
33
+ def style_transfer(image, style):
34
+ return image # Replace with real model later
35
+
36
+ # βœ… Gradio App Setup
37
+ with gr.Blocks() as demo:
38
+ gr.Markdown("# πŸš€ ML Playground Dashboard")
39
+
40
+ with gr.Tab("Sentiment Analyzer"):
41
+ gr.Interface(fn=analyze_sentiment, inputs=gr.Textbox(), outputs=gr.Textbox())
42
+
43
+ with gr.Tab("Toxic Comment Detector"):
44
+ gr.Interface(fn=detect_toxic, inputs=gr.Textbox(), outputs=gr.Textbox())
45
+
46
+ with gr.Tab("Image Caption Generator"):
47
+ gr.Interface(fn=caption_image, inputs=gr.Image(type="pil"), outputs=gr.Textbox())
48
+
49
+ with gr.Tab("Speech-to-Text"):
50
+ gr.Interface(fn=speech_to_text, inputs=gr.Audio(type="filepath"), outputs=gr.Textbox())
51
+
52
+ with gr.Tab("Art Style Transfer"):
53
+ gr.Interface(
54
+ fn=style_transfer,
55
+ inputs=[gr.Image(), gr.Dropdown(["Van Gogh", "Monet", "Picasso"])],
56
+ outputs=gr.Image()
57
+ )
58
+
59
+ demo.launch()