Update app.py
Browse files
app.py
CHANGED
|
@@ -6,137 +6,26 @@ import re
|
|
| 6 |
# Configurações de chave secreta e API do Google Gemini
|
| 7 |
API_KEY = st.secrets["GOOGLE_API_KEY"]
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
""
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
padding: 20px;
|
| 22 |
-
display: flex;
|
| 23 |
-
flex-wrap: wrap;
|
| 24 |
-
}
|
| 25 |
-
.stSidebar {
|
| 26 |
-
background-color: #e9ecef;
|
| 27 |
-
padding: 20px;
|
| 28 |
-
border-radius: 10px;
|
| 29 |
-
margin-bottom: 20px;
|
| 30 |
-
width: 250px;
|
| 31 |
-
min-width:250px;
|
| 32 |
-
}
|
| 33 |
-
@media (max-width: 768px) {
|
| 34 |
-
.stSidebar {
|
| 35 |
-
width: 100%;
|
| 36 |
-
margin-bottom: 10px;
|
| 37 |
-
min-width:auto;
|
| 38 |
-
}
|
| 39 |
-
}
|
| 40 |
-
.main{
|
| 41 |
-
flex: 1;
|
| 42 |
-
padding: 20px;
|
| 43 |
-
display: flex;
|
| 44 |
-
flex-direction:column;
|
| 45 |
-
}
|
| 46 |
-
.stTextInput>div>div>input {
|
| 47 |
-
width: 100%;
|
| 48 |
-
border-radius: 8px;
|
| 49 |
-
padding: 12px;
|
| 50 |
-
border: 1px solid #ced4da;
|
| 51 |
-
font-size: 1rem;
|
| 52 |
-
}
|
| 53 |
-
.stSelectbox>div>div>div {
|
| 54 |
-
border-radius: 8px;
|
| 55 |
-
padding: 10px;
|
| 56 |
-
border: 1px solid #ced4da;
|
| 57 |
-
font-size: 1rem;
|
| 58 |
-
margin-bottom: 10px;
|
| 59 |
-
}
|
| 60 |
-
.stRadio>div{
|
| 61 |
-
display:flex;
|
| 62 |
-
flex-direction: row;
|
| 63 |
-
margin-bottom: 10px;
|
| 64 |
-
}
|
| 65 |
-
.stRadio>div>div{
|
| 66 |
-
margin-right:15px
|
| 67 |
-
}
|
| 68 |
-
.stButton>button {
|
| 69 |
-
background-color: #007bff;
|
| 70 |
-
color: white;
|
| 71 |
-
border: none;
|
| 72 |
-
border-radius: 8px;
|
| 73 |
-
padding: 12px 24px;
|
| 74 |
-
cursor: pointer;
|
| 75 |
-
transition: background-color 0.3s ease;
|
| 76 |
-
font-size: 1rem;
|
| 77 |
-
}
|
| 78 |
-
.stButton>button:hover {
|
| 79 |
-
background-color: #0056b3;
|
| 80 |
-
}
|
| 81 |
-
.stDownloadButton>button{
|
| 82 |
-
background-color: #28a745;
|
| 83 |
-
color: white;
|
| 84 |
-
border: none;
|
| 85 |
-
border-radius: 8px;
|
| 86 |
-
padding: 12px 24px;
|
| 87 |
-
cursor: pointer;
|
| 88 |
-
transition: background-color 0.3s ease;
|
| 89 |
-
font-size: 1rem;
|
| 90 |
-
}
|
| 91 |
-
.stDownloadButton>button:hover {
|
| 92 |
-
background-color: #1e7e34;
|
| 93 |
-
}
|
| 94 |
-
.stAlert {
|
| 95 |
-
padding: 15px;
|
| 96 |
-
margin-bottom: 20px;
|
| 97 |
-
border: 1px solid transparent;
|
| 98 |
-
border-radius: 4px;
|
| 99 |
-
font-size: 1rem;
|
| 100 |
-
}
|
| 101 |
-
.stAlert.stAlert-danger {
|
| 102 |
-
color: #721c24;
|
| 103 |
-
background-color: #f8d7da;
|
| 104 |
-
border-color: #f5c6cb;
|
| 105 |
-
}
|
| 106 |
-
.stSpinner {
|
| 107 |
-
display: flex;
|
| 108 |
-
justify-content: center;
|
| 109 |
-
align-items: center;
|
| 110 |
-
margin-top: 20px;
|
| 111 |
-
}
|
| 112 |
-
.stSpinner div {
|
| 113 |
-
border: 8px solid #f3f3f3;
|
| 114 |
-
border-top: 8px solid #3498db;
|
| 115 |
-
border-radius: 50%;
|
| 116 |
-
width: 60px;
|
| 117 |
-
height: 60px;
|
| 118 |
-
animation: spin 2s linear infinite;
|
| 119 |
-
}
|
| 120 |
-
@keyframes spin {
|
| 121 |
-
0% { transform: rotate(0deg); }
|
| 122 |
-
100% { transform: rotate(360deg); }
|
| 123 |
-
}
|
| 124 |
-
code.language-powershell {
|
| 125 |
-
display: block;
|
| 126 |
-
overflow-x: auto;
|
| 127 |
-
background-color: #f5f5f5;
|
| 128 |
-
color: #333;
|
| 129 |
-
padding: 15px;
|
| 130 |
-
border-radius: 8px;
|
| 131 |
-
font-size: 0.9rem;
|
| 132 |
-
}
|
| 133 |
-
""",
|
| 134 |
-
unsafe_allow_html=True,
|
| 135 |
-
)
|
| 136 |
|
| 137 |
def enviar_mensagem_para_modelo(mensagem):
|
| 138 |
"""Envia uma mensagem para o modelo de IA e retorna a resposta."""
|
| 139 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
resposta = MODELO.start_chat(history=[]).send_message(mensagem)
|
| 141 |
return resposta.text
|
| 142 |
except Exception as e:
|
|
@@ -187,25 +76,7 @@ def parsear_e_salvar_ps1(codigo_ia, titulo_curto):
|
|
| 187 |
return nome_arquivo, codigo_ps1
|
| 188 |
|
| 189 |
def main():
|
| 190 |
-
|
| 191 |
-
CONFIGURACAO_GERACAO = {
|
| 192 |
-
"temperature": 0.2,
|
| 193 |
-
"top_p": 0.8,
|
| 194 |
-
"top_k": 40,
|
| 195 |
-
"response_mime_type": "text/plain",
|
| 196 |
-
}
|
| 197 |
-
NOME_MODELO = "gemini-2.0-flash-exp"
|
| 198 |
-
|
| 199 |
-
# Move st.set_page_config para o começo da função
|
| 200 |
-
st.set_page_config(page_title="Google Gemini 2 PowerShell Command Gen", page_icon="🤖", layout="wide")
|
| 201 |
-
|
| 202 |
-
# Configuração do modelo de IA
|
| 203 |
-
global MODELO
|
| 204 |
-
MODELO = genai.GenerativeModel(
|
| 205 |
-
model_name=NOME_MODELO,
|
| 206 |
-
generation_config=CONFIGURACAO_GERACAO,
|
| 207 |
-
)
|
| 208 |
-
|
| 209 |
st.title("🤖 Google Gemini 2 PowerShell Command Gen by [Elias Andrade](https://github.com/chaos4455)")
|
| 210 |
st.markdown("Crie comandos PowerShell de forma fácil e rápida!")
|
| 211 |
st.markdown("---")
|
|
@@ -214,15 +85,14 @@ def main():
|
|
| 214 |
col1, col2 = st.columns([1, 3])
|
| 215 |
|
| 216 |
with col1:
|
| 217 |
-
st.
|
| 218 |
-
powershell_version = st.
|
| 219 |
-
sistema_operacional = st.
|
| 220 |
|
| 221 |
-
nivel_detalhe = st.
|
| 222 |
-
tipo_script = st.
|
| 223 |
-
nivel_seguranca = st.
|
| 224 |
with col2:
|
| 225 |
-
|
| 226 |
# Prompt base do usuário
|
| 227 |
prompt_base = st.text_input("Descreva o Comando PowerShell:", placeholder="Ex: Liste todos os processos em execução", key="prompt_base")
|
| 228 |
|
|
|
|
| 6 |
# Configurações de chave secreta e API do Google Gemini
|
| 7 |
API_KEY = st.secrets["GOOGLE_API_KEY"]
|
| 8 |
|
| 9 |
+
# Configuração do modelo de IA (fora da main)
|
| 10 |
+
CONFIGURACAO_GERACAO = {
|
| 11 |
+
"temperature": 0.2,
|
| 12 |
+
"top_p": 0.8,
|
| 13 |
+
"top_k": 40,
|
| 14 |
+
"response_mime_type": "text/plain",
|
| 15 |
+
}
|
| 16 |
+
NOME_MODELO = "gemini-2.0-flash-exp"
|
| 17 |
+
|
| 18 |
+
# Configuração da página
|
| 19 |
+
st.set_page_config(page_title="Google Gemini 2 PowerShell Command Gen", page_icon="🤖", layout="wide")
|
| 20 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def enviar_mensagem_para_modelo(mensagem):
|
| 23 |
"""Envia uma mensagem para o modelo de IA e retorna a resposta."""
|
| 24 |
try:
|
| 25 |
+
MODELO = genai.GenerativeModel(
|
| 26 |
+
model_name=NOME_MODELO,
|
| 27 |
+
generation_config=CONFIGURACAO_GERACAO,
|
| 28 |
+
)
|
| 29 |
resposta = MODELO.start_chat(history=[]).send_message(mensagem)
|
| 30 |
return resposta.text
|
| 31 |
except Exception as e:
|
|
|
|
| 76 |
return nome_arquivo, codigo_ps1
|
| 77 |
|
| 78 |
def main():
|
| 79 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
st.title("🤖 Google Gemini 2 PowerShell Command Gen by [Elias Andrade](https://github.com/chaos4455)")
|
| 81 |
st.markdown("Crie comandos PowerShell de forma fácil e rápida!")
|
| 82 |
st.markdown("---")
|
|
|
|
| 85 |
col1, col2 = st.columns([1, 3])
|
| 86 |
|
| 87 |
with col1:
|
| 88 |
+
st.header("⚙️ Configurações")
|
| 89 |
+
powershell_version = st.selectbox("Versão do PowerShell", ["7", "5.1"], index=0)
|
| 90 |
+
sistema_operacional = st.selectbox("Sistema Operacional", ["Windows Server 2016", "Windows 10", "Windows 11", "Outro"], index=0)
|
| 91 |
|
| 92 |
+
nivel_detalhe = st.selectbox("Nível de Detalhe", ["Mais detalhado", "Padrão", "Mais conciso"], index=1)
|
| 93 |
+
tipo_script = st.selectbox("Tipo de Script", ["Mais automático", "Mais interativo"], index=0)
|
| 94 |
+
nivel_seguranca = st.radio("Nível de Segurança", ["Alto", "Médio", "Baixo"], index=1)
|
| 95 |
with col2:
|
|
|
|
| 96 |
# Prompt base do usuário
|
| 97 |
prompt_base = st.text_input("Descreva o Comando PowerShell:", placeholder="Ex: Liste todos os processos em execução", key="prompt_base")
|
| 98 |
|