chaos4455 commited on
Commit
6d0cadc
·
verified ·
1 Parent(s): 7c724c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +177 -130
app.py CHANGED
@@ -6,19 +6,149 @@ import re
6
  # Configurações de chave secreta e API do Google Gemini
7
  API_KEY = st.secrets["GOOGLE_API_KEY"]
8
 
 
9
  # Estilos CSS para o Streamlit
10
- # Removido do escopo global
11
- # st.markdown( ... )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- # Removido do escopo global
14
- # st.set_page_config( ... )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
 
17
  def enviar_mensagem_para_modelo(mensagem):
18
  """Envia uma mensagem para o modelo de IA e retorna a resposta."""
19
  try:
20
- # Removido do escopo global
21
- # MODELO = genai.GenerativeModel(model_name=NOME_MODELO, generation_config=CONFIGURACAO_GERACAO)
22
  resposta = MODELO.start_chat(history=[]).send_message(mensagem)
23
  return resposta.text
24
  except Exception as e:
@@ -79,7 +209,7 @@ def main():
79
  NOME_MODELO = "gemini-2.0-flash-exp"
80
 
81
  # Move st.set_page_config para o começo da função
82
- st.set_page_config(page_title="Google Gemini 2 PowerShell Command Gen", page_icon="🤖")
83
 
84
 
85
  # Configuração do modelo de IA
@@ -88,135 +218,52 @@ def main():
88
  model_name=NOME_MODELO,
89
  generation_config=CONFIGURACAO_GERACAO,
90
  )
91
-
92
- # Estilos CSS para o Streamlit
93
- st.markdown(
94
- """
95
- <style>
96
- body {
97
- background-color: #f0f2f6;
98
- color: #262730;
99
- }
100
- .stApp {
101
- max-width: 900px;
102
- margin: 0 auto;
103
- padding: 20px;
104
- }
105
- .stTextInput>div>div>input {
106
- border-radius: 8px;
107
- padding: 10px;
108
- border: 1px solid #ced4da;
109
- }
110
- .stButton>button {
111
- background-color: #007bff;
112
- color: white;
113
- border: none;
114
- border-radius: 8px;
115
- padding: 10px 20px;
116
- cursor: pointer;
117
- }
118
- .stButton>button:hover {
119
- background-color: #0056b3;
120
- }
121
- .stSelectbox>div>div>div {
122
- border-radius: 8px;
123
- padding: 5px;
124
- border: 1px solid #ced4da;
125
-
126
- }
127
- .stRadio>div{
128
- display:flex;
129
- flex-direction: row;
130
- }
131
- .stRadio>div>div{
132
- margin-right:15px
133
- }
134
- .stDownloadButton>button{
135
- background-color: #28a745;
136
- color: white;
137
- border: none;
138
- border-radius: 8px;
139
- padding: 10px 20px;
140
- cursor: pointer;
141
- }
142
- .stDownloadButton>button:hover {
143
- background-color: #1e7e34;
144
- }
145
-
146
- .stAlert {
147
- padding: 15px;
148
- margin-bottom: 20px;
149
- border: 1px solid transparent;
150
- border-radius: 4px;
151
- }
152
- .stAlert.stAlert-danger {
153
- color: #721c24;
154
- background-color: #f8d7da;
155
- border-color: #f5c6cb;
156
- }
157
- .stSpinner {
158
- display: flex;
159
- justify-content: center;
160
- align-items: center;
161
- margin-top: 20px;
162
- }
163
- .stSpinner div {
164
- border: 8px solid #f3f3f3;
165
- border-top: 8px solid #3498db;
166
- border-radius: 50%;
167
- width: 60px;
168
- height: 60px;
169
- animation: spin 2s linear infinite;
170
- }
171
 
172
- @keyframes spin {
173
- 0% { transform: rotate(0deg); }
174
- 100% { transform: rotate(360deg); }
175
- }
176
- </style>
177
- """,
178
- unsafe_allow_html=True,
179
- )
180
 
181
  st.title("🤖 Google Gemini 2 PowerShell Command Gen by [Elias Andrade](https://github.com/chaos4455)")
182
  st.markdown("Crie comandos PowerShell de forma fácil e rápida!")
183
  st.markdown("---")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
 
185
- # Configurações do Usuário
186
- st.sidebar.header("⚙️ Configurações")
187
- powershell_version = st.sidebar.selectbox("Versão do PowerShell", ["7", "5.1"], index=0)
188
- sistema_operacional = st.sidebar.selectbox("Sistema Operacional", ["Windows Server 2016", "Windows 10", "Windows 11", "Outro"], index=0)
189
-
190
- nivel_detalhe = st.sidebar.selectbox("Nível de Detalhe", ["Mais detalhado", "Padrão", "Mais conciso"], index=1)
191
- tipo_script = st.sidebar.selectbox("Tipo de Script", ["Mais automático", "Mais interativo"], index=0)
192
- nivel_seguranca = st.sidebar.radio("Nível de Segurança", ["Alto", "Médio", "Baixo"], index=1)
193
-
194
- # Prompt base do usuário
195
- prompt_base = st.text_input("Descreva o Comando PowerShell:", placeholder="Ex: Liste todos os processos em execução", key="prompt_base")
196
-
197
- if st.button("✨ Gerar Comando PowerShell"):
198
- if not prompt_base:
199
- st.error("⚠️ Por favor, insira uma descrição do comando.")
200
- return
201
-
202
- with st.spinner("⏳ Gerando comando..."):
203
- codigo_ia = gerar_comando_powershell(prompt_base, nivel_detalhe, tipo_script, nivel_seguranca)
204
- if codigo_ia:
205
-
206
- st.markdown("### ✅ Comando Gerado:")
207
- st.code(codigo_ia, language="powershell")
208
-
209
- titulo_curto = prompt_base[:30].strip().replace(" ", "_").lower()
210
- nome_arquivo_ps1, codigo_ps1 = parsear_e_salvar_ps1(codigo_ia, titulo_curto)
211
-
212
- st.download_button(
213
- label="⬇️ Baixar Comando (.ps1)",
214
- data=codigo_ps1,
215
- file_name=nome_arquivo_ps1,
216
- mime="application/powershell",
217
- )
218
- else:
219
- st.error("❌ Erro ao gerar o comando. Verifique a conexão com a IA e tente novamente.")
220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  if __name__ == "__main__":
222
  main()
 
6
  # Configurações de chave secreta e API do Google Gemini
7
  API_KEY = st.secrets["GOOGLE_API_KEY"]
8
 
9
+
10
  # Estilos CSS para o Streamlit
11
+ st.markdown(
12
+ """
13
+ <style>
14
+ body {
15
+ background-color: #f0f2f6;
16
+ color: #262730;
17
+ font-family: 'Arial', sans-serif; /* Fonte padrão */
18
+ }
19
+ .stApp {
20
+ max-width: 1200px;
21
+ margin: 0 auto;
22
+ padding: 20px;
23
+ display: flex;
24
+ flex-wrap: wrap; /* Quebra em telas menores */
25
+
26
+ }
27
+
28
+ /* Barra Lateral */
29
+ .stSidebar {
30
+ background-color: #e9ecef;
31
+ padding: 20px;
32
+ border-radius: 10px;
33
+ margin-bottom: 20px;
34
+ width: 250px; /* Largura da barra lateral */
35
+ min-width:250px;
36
+
37
+ }
38
+ @media (max-width: 768px) {
39
+ .stSidebar {
40
+ width: 100%;
41
+ margin-bottom: 10px;
42
+ min-width:auto;
43
+ }
44
+ }
45
+ /* Conteúdo Principal */
46
+ .main{
47
+ flex: 1;
48
+ padding: 20px; /* Espaço interno */
49
+ display: flex;
50
+ flex-direction:column; /* empilhamento do conteudo */
51
+
52
+ }
53
+ .stTextInput>div>div>input {
54
+ width: 100%;
55
+ border-radius: 8px;
56
+ padding: 12px;
57
+ border: 1px solid #ced4da;
58
+ font-size: 1rem;
59
+ }
60
+ .stSelectbox>div>div>div {
61
+ border-radius: 8px;
62
+ padding: 10px;
63
+ border: 1px solid #ced4da;
64
+ font-size: 1rem;
65
+ margin-bottom: 10px;
66
+
67
+ }
68
+ .stRadio>div{
69
+ display:flex;
70
+ flex-direction: row;
71
+ margin-bottom: 10px;
72
+ }
73
+ .stRadio>div>div{
74
+ margin-right:15px
75
+ }
76
+ .stButton>button {
77
+ background-color: #007bff;
78
+ color: white;
79
+ border: none;
80
+ border-radius: 8px;
81
+ padding: 12px 24px;
82
+ cursor: pointer;
83
+ transition: background-color 0.3s ease;
84
+ font-size: 1rem;
85
+ }
86
+ .stButton>button:hover {
87
+ background-color: #0056b3;
88
+ }
89
+ .stDownloadButton>button{
90
+ background-color: #28a745;
91
+ color: white;
92
+ border: none;
93
+ border-radius: 8px;
94
+ padding: 12px 24px;
95
+ cursor: pointer;
96
+ transition: background-color 0.3s ease;
97
+ font-size: 1rem;
98
+ }
99
+ .stDownloadButton>button:hover {
100
+ background-color: #1e7e34;
101
+ }
102
 
103
+ .stAlert {
104
+ padding: 15px;
105
+ margin-bottom: 20px;
106
+ border: 1px solid transparent;
107
+ border-radius: 4px;
108
+ font-size: 1rem;
109
+ }
110
+ .stAlert.stAlert-danger {
111
+ color: #721c24;
112
+ background-color: #f8d7da;
113
+ border-color: #f5c6cb;
114
+ }
115
+ .stSpinner {
116
+ display: flex;
117
+ justify-content: center;
118
+ align-items: center;
119
+ margin-top: 20px;
120
+ }
121
+ .stSpinner div {
122
+ border: 8px solid #f3f3f3;
123
+ border-top: 8px solid #3498db;
124
+ border-radius: 50%;
125
+ width: 60px;
126
+ height: 60px;
127
+ animation: spin 2s linear infinite;
128
+ }
129
+
130
+ @keyframes spin {
131
+ 0% { transform: rotate(0deg); }
132
+ 100% { transform: rotate(360deg); }
133
+ }
134
+ code.language-powershell {
135
+ display: block; /* Para ocupar toda a largura */
136
+ overflow-x: auto; /* Barra de rolagem horizontal se necessário */
137
+ background-color: #f5f5f5;
138
+ color: #333;
139
+ padding: 15px;
140
+ border-radius: 8px;
141
+ font-size: 0.9rem;
142
+ }
143
+ """,
144
+ unsafe_allow_html=True,
145
+ )
146
 
147
 
148
  def enviar_mensagem_para_modelo(mensagem):
149
  """Envia uma mensagem para o modelo de IA e retorna a resposta."""
150
  try:
151
+
 
152
  resposta = MODELO.start_chat(history=[]).send_message(mensagem)
153
  return resposta.text
154
  except Exception as e:
 
209
  NOME_MODELO = "gemini-2.0-flash-exp"
210
 
211
  # Move st.set_page_config para o começo da função
212
+ st.set_page_config(page_title="Google Gemini 2 PowerShell Command Gen", page_icon="🤖", layout="wide")
213
 
214
 
215
  # Configuração do modelo de IA
 
218
  model_name=NOME_MODELO,
219
  generation_config=CONFIGURACAO_GERACAO,
220
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
 
222
+
 
 
 
 
 
 
 
223
 
224
  st.title("🤖 Google Gemini 2 PowerShell Command Gen by [Elias Andrade](https://github.com/chaos4455)")
225
  st.markdown("Crie comandos PowerShell de forma fácil e rápida!")
226
  st.markdown("---")
227
+
228
+ # Layout em colunas (barra lateral e principal)
229
+ col1, col2 = st.columns([1, 3])
230
+
231
+ with col1:
232
+ st.sidebar.header("⚙️ Configurações")
233
+ powershell_version = st.sidebar.selectbox("Versão do PowerShell", ["7", "5.1"], index=0)
234
+ sistema_operacional = st.sidebar.selectbox("Sistema Operacional", ["Windows Server 2016", "Windows 10", "Windows 11", "Outro"], index=0)
235
+
236
+ nivel_detalhe = st.sidebar.selectbox("Nível de Detalhe", ["Mais detalhado", "Padrão", "Mais conciso"], index=1)
237
+ tipo_script = st.sidebar.selectbox("Tipo de Script", ["Mais automático", "Mais interativo"], index=0)
238
+ nivel_seguranca = st.sidebar.radio("Nível de Segurança", ["Alto", "Médio", "Baixo"], index=1)
239
+ with col2:
240
+
241
+ # Prompt base do usuário
242
+ prompt_base = st.text_input("Descreva o Comando PowerShell:", placeholder="Ex: Liste todos os processos em execução", key="prompt_base")
243
 
244
+ if st.button("✨ Gerar Comando PowerShell"):
245
+ if not prompt_base:
246
+ st.error("⚠️ Por favor, insira uma descrição do comando.")
247
+ return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
 
249
+ with st.spinner("⏳ Gerando comando..."):
250
+ codigo_ia = gerar_comando_powershell(prompt_base, nivel_detalhe, tipo_script, nivel_seguranca)
251
+ if codigo_ia:
252
+
253
+ st.markdown("### ✅ Comando Gerado:")
254
+ st.code(codigo_ia, language="powershell")
255
+
256
+ titulo_curto = prompt_base[:30].strip().replace(" ", "_").lower()
257
+ nome_arquivo_ps1, codigo_ps1 = parsear_e_salvar_ps1(codigo_ia, titulo_curto)
258
+
259
+ st.download_button(
260
+ label="⬇️ Baixar Comando (.ps1)",
261
+ data=codigo_ps1,
262
+ file_name=nome_arquivo_ps1,
263
+ mime="application/powershell",
264
+ )
265
+ else:
266
+ st.error("❌ Erro ao gerar o comando. Verifique a conexão com a IA e tente novamente.")
267
+
268
  if __name__ == "__main__":
269
  main()