Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from zipfile import ZipFile
|
|
5 |
from huggingface_hub import InferenceClient
|
6 |
|
7 |
# Configuração do modelo e token de autenticação
|
8 |
-
MODEL_NAME = "microsoft/codebert-base" #
|
9 |
TOKEN = os.getenv("HF_TOKEN", "") # Defina a variável de ambiente HF_TOKEN com seu token de acesso
|
10 |
client = InferenceClient(model=MODEL_NAME, token=TOKEN)
|
11 |
|
@@ -52,19 +52,17 @@ def chat_with_codebert(chat_history, user_input):
|
|
52 |
return f"Erro ao processar a resposta da IA: {e}"
|
53 |
|
54 |
# Interface de upload
|
55 |
-
def upload_and_analyze(
|
56 |
# Salvar o arquivo ZIP enviado
|
57 |
if not os.path.exists(UPLOAD_DIR):
|
58 |
os.makedirs(UPLOAD_DIR)
|
59 |
-
zip_path = os.path.join(UPLOAD_DIR, zip_file.name)
|
60 |
-
with open(zip_path, "wb") as f:
|
61 |
-
f.write(zip_file.read())
|
62 |
|
63 |
# Processar o ZIP para análise
|
64 |
try:
|
65 |
-
analysis = process_uploaded_folder(
|
66 |
finally:
|
67 |
-
os.
|
|
|
68 |
return analysis
|
69 |
|
70 |
# Interface gráfica com Gradio
|
@@ -72,7 +70,7 @@ with gr.Blocks() as demo:
|
|
72 |
gr.Markdown("# Analisador de APK com CodeBERT 🚀")
|
73 |
|
74 |
with gr.Tab("Upload e Análise"):
|
75 |
-
upload_input = gr.File(label="Envie um arquivo ZIP com o código Java", type="
|
76 |
analysis_output = gr.Textbox(label="Resultado da Análise", lines=20)
|
77 |
analyze_button = gr.Button("Analisar")
|
78 |
analyze_button.click(upload_and_analyze, inputs=upload_input, outputs=analysis_output)
|
|
|
5 |
from huggingface_hub import InferenceClient
|
6 |
|
7 |
# Configuração do modelo e token de autenticação
|
8 |
+
MODEL_NAME = "microsoft/codebert-base" # Modelo CodeBERT
|
9 |
TOKEN = os.getenv("HF_TOKEN", "") # Defina a variável de ambiente HF_TOKEN com seu token de acesso
|
10 |
client = InferenceClient(model=MODEL_NAME, token=TOKEN)
|
11 |
|
|
|
52 |
return f"Erro ao processar a resposta da IA: {e}"
|
53 |
|
54 |
# Interface de upload
|
55 |
+
def upload_and_analyze(zip_file_path):
|
56 |
# Salvar o arquivo ZIP enviado
|
57 |
if not os.path.exists(UPLOAD_DIR):
|
58 |
os.makedirs(UPLOAD_DIR)
|
|
|
|
|
|
|
59 |
|
60 |
# Processar o ZIP para análise
|
61 |
try:
|
62 |
+
analysis = process_uploaded_folder(zip_file_path)
|
63 |
finally:
|
64 |
+
if os.path.exists(zip_file_path):
|
65 |
+
os.remove(zip_file_path) # Remover o arquivo ZIP após processamento
|
66 |
return analysis
|
67 |
|
68 |
# Interface gráfica com Gradio
|
|
|
70 |
gr.Markdown("# Analisador de APK com CodeBERT 🚀")
|
71 |
|
72 |
with gr.Tab("Upload e Análise"):
|
73 |
+
upload_input = gr.File(label="Envie um arquivo ZIP com o código Java", type="filepath") # Corrigido para usar `filepath`
|
74 |
analysis_output = gr.Textbox(label="Resultado da Análise", lines=20)
|
75 |
analyze_button = gr.Button("Analisar")
|
76 |
analyze_button.click(upload_and_analyze, inputs=upload_input, outputs=analysis_output)
|