DHEIVER commited on
Commit
c357e49
·
verified ·
1 Parent(s): 3a68dbf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +166 -118
app.py CHANGED
@@ -1,118 +1,166 @@
1
- <!DOCTYPE html>
2
- <html lang="pt-BR">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Central de IA - Bem-vindo</title>
6
- <style>
7
- .container {
8
- max-width: 800px;
9
- margin: 2rem auto;
10
- padding: 0 1rem;
11
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
12
- }
13
-
14
- .header {
15
- text-align: center;
16
- margin-bottom: 3rem;
17
- padding: 2rem;
18
- background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
19
- border-radius: 1rem;
20
- color: white;
21
- }
22
-
23
- .header h1 {
24
- margin: 0;
25
- font-size: 2.5rem;
26
- font-weight: 700;
27
- }
28
-
29
- .header p {
30
- margin: 1rem 0 0;
31
- font-size: 1.1rem;
32
- opacity: 0.9;
33
- }
34
-
35
- .features {
36
- display: grid;
37
- grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
38
- gap: 2rem;
39
- margin: 3rem 0;
40
- }
41
-
42
- .feature-card {
43
- padding: 1.5rem;
44
- background: white;
45
- border-radius: 0.75rem;
46
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
47
- transition: transform 0.2s;
48
- }
49
-
50
- .feature-card:hover {
51
- transform: translateY(-4px);
52
- }
53
-
54
- .feature-icon {
55
- font-size: 2rem;
56
- margin-bottom: 1rem;
57
- }
58
-
59
- .feature-title {
60
- font-size: 1.25rem;
61
- font-weight: 600;
62
- margin-bottom: 0.5rem;
63
- color: #1f2937;
64
- }
65
-
66
- .feature-description {
67
- color: #6b7280;
68
- line-height: 1.5;
69
- }
70
-
71
- .footer {
72
- text-align: center;
73
- margin-top: 3rem;
74
- padding: 2rem;
75
- color: #6b7280;
76
- border-top: 1px solid #e5e7eb;
77
- }
78
- </style>
79
- </head>
80
- <body>
81
- <div class="container">
82
- <header class="header">
83
- <h1>Central de Inteligência Artificial</h1>
84
- <p>Uma plataforma completa com ferramentas de IA para suas necessidades</p>
85
- </header>
86
-
87
- <div class="features">
88
- <div class="feature-card">
89
- <div class="feature-icon">📝</div>
90
- <h3 class="feature-title">Transcrição de Áudio</h3>
91
- <p class="feature-description">Converta áudio em texto com precisão usando tecnologia de ponta em reconhecimento de fala.</p>
92
- </div>
93
-
94
- <div class="feature-card">
95
- <div class="feature-icon">🔄</div>
96
- <h3 class="feature-title">Tradução</h3>
97
- <p class="feature-description">Traduza textos entre português e inglês com nossa ferramenta de tradução neural.</p>
98
- </div>
99
-
100
- <div class="feature-card">
101
- <div class="feature-icon">📊</div>
102
- <h3 class="feature-title">Análise de Texto</h3>
103
- <p class="feature-description">Gere resumos automáticos e analise o sentimento de textos com facilidade.</p>
104
- </div>
105
-
106
- <div class="feature-card">
107
- <div class="feature-icon">🤖</div>
108
- <h3 class="feature-title">IA Avançada</h3>
109
- <p class="feature-description">Experimente nosso chatbot inteligente e classificação automática de textos.</p>
110
- </div>
111
- </div>
112
-
113
- <footer class="footer">
114
- <p>Desenvolvido com tecnologia de ponta em Inteligência Artificial</p>
115
- </footer>
116
- </div>
117
- </body>
118
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import torch
4
+ import warnings
5
+ import numpy as np
6
+ from PIL import Image
7
+ warnings.filterwarnings('ignore')
8
+
9
+ device = "cuda" if torch.cuda.is_available() else "cpu"
10
+
11
+ # Dicionário expandido de modelos
12
+ models = {
13
+ 'transcription': pipeline("automatic-speech-recognition", model="openai/whisper-small", device=device),
14
+ 'translation': pipeline("translation", model="facebook/mbart-large-50-many-to-many-mmt", device=device),
15
+ 'summarization': pipeline("summarization", model="facebook/bart-large-cnn", device=device),
16
+ 'sentiment': pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment", device=device),
17
+ 'question_answering': pipeline("question-answering", model="deepset/roberta-base-squad2", device=device),
18
+ 'chat': pipeline("text-generation", model="facebook/opt-125m", device=device),
19
+ 'image_caption': pipeline("image-to-text", model="Salesforce/blip-image-captioning-base", device=device),
20
+ 'text_to_speech': pipeline("text-to-audio", model="facebook/mms-tts-eng", device=device),
21
+ 'zero_shot': pipeline("zero-shot-classification", model="facebook/bart-large-mnli", device=device),
22
+ 'ner': pipeline("token-classification", model="dslim/bert-base-NER", device=device)
23
+ }
24
+
25
+ def process_transcription(audio):
26
+ if not audio:
27
+ return "Por favor, forneça um arquivo de áudio."
28
+ return models['transcription'](audio)["text"]
29
+
30
+ def process_translation(text, direction):
31
+ if not text:
32
+ return "Por favor, forneça um texto para tradução."
33
+ return models['translation'](text,
34
+ src_lang="pt" if direction=="pt_en" else "en",
35
+ tgt_lang="en" if direction=="pt_en" else "pt")[0]['translation_text']
36
+
37
+ def process_summarization(text):
38
+ if not text:
39
+ return "Por favor, forneça um texto para resumir."
40
+ return models['summarization'](text, max_length=130, min_length=30)[0]['summary_text']
41
+
42
+ def process_sentiment(text):
43
+ if not text:
44
+ return "Por favor, forneça um texto para análise."
45
+ result = models['sentiment'](text)[0]
46
+ return f"Sentimento: {result['label']} (Score: {result['score']:.2f})"
47
+
48
+ def process_qa(question, context):
49
+ if not question or not context:
50
+ return "Por favor, forneça tanto a pergunta quanto o contexto."
51
+ return models['question_answering'](question=question, context=context)['answer']
52
+
53
+ def process_chat(message, history):
54
+ if not message:
55
+ return "", history
56
+ response = models['chat'](message, max_length=100, do_sample=True)[0]['generated_text']
57
+ history = history + [(message, response)]
58
+ return "", history
59
+
60
+ def process_image_caption(image):
61
+ if image is None:
62
+ return "Por favor, forneça uma imagem."
63
+ return models['image_caption'](image)[0]['generated_text']
64
+
65
+ def process_tts(text):
66
+ if not text:
67
+ return None
68
+ return models['text_to_speech'](text)
69
+
70
+ def process_zero_shot(text, labels):
71
+ if not text or not labels:
72
+ return "Por favor, forneça texto e categorias."
73
+ result = models['zero_shot'](text, labels.split(','))
74
+ return f"Classificação: {result['labels'][0]} (Confiança: {result['scores'][0]:.2f})"
75
+
76
+ def process_ner(text):
77
+ if not text:
78
+ return "Por favor, forneça um texto para análise."
79
+ results = models['ner'](text)
80
+ entities = []
81
+ for result in results:
82
+ entities.append(f"{result['word']}: {result['entity']}")
83
+ return "\n".join(entities)
84
+
85
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
86
+ gr.HTML(open("index.html").read())
87
+
88
+ with gr.Tabs():
89
+ # Aba de Processamento de Áudio
90
+ with gr.TabItem("🎤 Áudio"):
91
+ with gr.Tabs():
92
+ with gr.TabItem("Transcrição"):
93
+ audio_input = gr.Audio(type="filepath")
94
+ transcribe_button = gr.Button("Transcrever")
95
+ transcription_output = gr.Textbox(label="Resultado")
96
+ transcribe_button.click(process_transcription, inputs=audio_input, outputs=transcription_output)
97
+
98
+ with gr.TabItem("Texto para Fala"):
99
+ tts_input = gr.Textbox(label="Texto para Converter")
100
+ tts_button = gr.Button("Converter para Áudio")
101
+ tts_output = gr.Audio(label="Áudio Gerado")
102
+ tts_button.click(process_tts, inputs=tts_input, outputs=tts_output)
103
+
104
+ # Aba de Processamento de Texto
105
+ with gr.TabItem("📝 Texto"):
106
+ with gr.Tabs():
107
+ with gr.TabItem("Tradução"):
108
+ with gr.Row():
109
+ text_to_translate = gr.Textbox(label="Texto")
110
+ translation_direction = gr.Radio(["en_pt", "pt_en"], value="en_pt", label="Direção")
111
+ translate_button = gr.Button("Traduzir")
112
+ translation_output = gr.Textbox(label="Resultado")
113
+ translate_button.click(process_translation, inputs=[text_to_translate, translation_direction], outputs=translation_output)
114
+
115
+ with gr.TabItem("Resumo"):
116
+ text_sum = gr.Textbox(label="Texto", lines=5)
117
+ sum_button = gr.Button("Resumir")
118
+ sum_output = gr.Textbox(label="Resultado")
119
+ sum_button.click(process_summarization, inputs=text_sum, outputs=sum_output)
120
+
121
+ with gr.TabItem("Perguntas e Respostas"):
122
+ qa_context = gr.Textbox(label="Contexto", lines=5)
123
+ qa_question = gr.Textbox(label="Pergunta")
124
+ qa_button = gr.Button("Obter Resposta")
125
+ qa_output = gr.Textbox(label="Resposta")
126
+ qa_button.click(process_qa, inputs=[qa_question, qa_context], outputs=qa_output)
127
+
128
+ # Aba de Análise
129
+ with gr.TabItem("📊 Análise"):
130
+ with gr.Tabs():
131
+ with gr.TabItem("Sentimento"):
132
+ text_sent = gr.Textbox(label="Texto")
133
+ sent_button = gr.Button("Analisar Sentimento")
134
+ sent_output = gr.Textbox(label="Resultado")
135
+ sent_button.click(process_sentiment, inputs=text_sent, outputs=sent_output)
136
+
137
+ with gr.TabItem("Entidades Nomeadas"):
138
+ ner_input = gr.Textbox(label="Texto")
139
+ ner_button = gr.Button("Identificar Entidades")
140
+ ner_output = gr.Textbox(label="Entidades Identificadas")
141
+ ner_button.click(process_ner, inputs=ner_input, outputs=ner_output)
142
+
143
+ with gr.TabItem("Classificação Zero-Shot"):
144
+ zero_text = gr.Textbox(label="Texto")
145
+ zero_labels = gr.Textbox(label="Categorias (separadas por vírgula)")
146
+ zero_button = gr.Button("Classificar")
147
+ zero_output = gr.Textbox(label="Resultado")
148
+ zero_button.click(process_zero_shot, inputs=[zero_text, zero_labels], outputs=zero_output)
149
+
150
+ # Aba de IA Avançada
151
+ with gr.TabItem("🤖 IA Avançada"):
152
+ with gr.Tabs():
153
+ with gr.TabItem("Chat"):
154
+ chatbot = gr.Chatbot()
155
+ msg = gr.Textbox(label="Mensagem")
156
+ clear = gr.Button("Limpar Conversa")
157
+ msg.submit(process_chat, inputs=[msg, chatbot], outputs=[msg, chatbot])
158
+ clear.click(lambda: None, None, chatbot, queue=False)
159
+
160
+ with gr.TabItem("Descrição de Imagens"):
161
+ image_input = gr.Image()
162
+ caption_button = gr.Button("Gerar Descrição")
163
+ caption_output = gr.Textbox(label="Descrição")
164
+ caption_button.click(process_image_caption, inputs=image_input, outputs=caption_output)
165
+
166
+ demo.launch(share=True)