Pixel101 commited on
Commit
198a28d
·
verified ·
1 Parent(s): 03b2869

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -103
app.py DELETED
@@ -1,103 +0,0 @@
1
- # Install necessary libraries
2
-
3
- import gradio as gr
4
- from transformers import pipeline
5
-
6
- # Load models
7
- # Sentiment Analysis
8
- classifier_sentiment = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
9
-
10
- def analyze_sentiment(text):
11
- result = classifier_sentiment(text)[0]
12
- label = result['label']
13
- score = result['score']
14
- return f"Label: {label}, Score: {score:.2f}"
15
-
16
- # Translation
17
- translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fr")
18
-
19
- def translate_text(text):
20
- result = translator(text)[0]
21
- translated_text = result["translation_text"]
22
- return translated_text
23
-
24
- # Image Classification
25
- classifier_image = pipeline("image-classification", model="google/mobilenet_v2_1.0_224")
26
-
27
- def classify_image(image):
28
- results = classifier_image(image)
29
- output = ""
30
- for result in results:
31
- output += f"{result['label']}: {result['score']:.2f}\n"
32
- return output
33
-
34
- # Speech to Text
35
- speech_to_text = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h")
36
-
37
- def transcribe_audio(audio):
38
- text = speech_to_text(audio)["text"]
39
- return text
40
-
41
- # Text Summarization
42
- summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
43
-
44
- def summarize_text(text):
45
- summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]["summary_text"]
46
- return summary
47
-
48
- # Define custom CSS styles
49
- css = """
50
- <style>
51
- body {
52
- background-color: #e9ecef;
53
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
54
- }
55
- .gradio-container {
56
- border-radius: 15px;
57
- box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
58
- padding: 20px;
59
- background-color: #74748a;
60
- max-width: 800px;
61
- margin: auto;
62
- }
63
- h1 {
64
- color: black;
65
- }
66
-
67
- </style>
68
- """
69
-
70
- with gr.Blocks(css=css) as demo:
71
- gr.Markdown("<h1 style='text-align: center;'>Multi-functional AI Demo</h1>")
72
-
73
- with gr.Tab("Sentiment Analysis😣"):
74
- text_input = gr.Textbox(placeholder="Enter text here...")
75
- text_output = gr.Textbox()
76
- sentiment_button = gr.Button("Analyze")
77
- sentiment_button.click(analyze_sentiment, inputs=text_input, outputs=text_output)
78
-
79
- with gr.Tab("Translation📚"):
80
- text_input_trans = gr.Textbox(placeholder="Enter English text here...")
81
- text_output_trans = gr.Textbox()
82
- trans_button = gr.Button("Translate")
83
- trans_button.click(translate_text, inputs=text_input_trans, outputs=text_output_trans)
84
-
85
- with gr.Tab("Image Classification🔮"):
86
- image_input = gr.Image(type="pil")
87
- image_output = gr.Textbox()
88
- image_button = gr.Button("Classify")
89
- image_button.click(classify_image, inputs=image_input, outputs=image_output)
90
-
91
- with gr.Tab("Speech to Text🔊"):
92
- audio_input = gr.Audio(sources=["microphone"], type="filepath")
93
- audio_output = gr.Textbox()
94
- audio_button = gr.Button("Transcribe")
95
- audio_button.click(transcribe_audio, inputs=audio_input, outputs=audio_output)
96
-
97
- with gr.Tab("Text Summarization📑"):
98
- text_input_summ = gr.Textbox(placeholder="Enter text here...")
99
- text_output_summ = gr.Textbox()
100
- summ_button = gr.Button("Summarize")
101
- summ_button.click(summarize_text, inputs=text_input_summ, outputs=text_output_summ)
102
-
103
- demo.launch()