Nextspace commited on
Commit
70f9a89
·
verified ·
1 Parent(s): 2f54d3f

update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -4
app.py CHANGED
@@ -53,7 +53,81 @@ Requisitos: {prompt}"""
53
  code = output.split("```")[1][len(language)+1:] if "```" in output else output
54
  exec_time = time.time() - start_time
55
 
56
- # Formatação Markdown
57
- response = f"""
58
- ```{language}
59
- {code.strip()}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  code = output.split("```")[1][len(language)+1:] if "```" in output else output
54
  exec_time = time.time() - start_time
55
 
56
+ # Formatação corrigida (string terminada corretamente)
57
+ response = f"""```{language}
58
+ {code.strip()}
59
+
60
+ ⏱️ Gerado em {exec_time:.2f}s | {LANGUAGES[language]['icon']} {language.upper()}"""
61
+ chat_history.append((prompt, response))
62
+ return "", chat_history
63
+
64
+ except Exception as e:
65
+ error_msg = f"❌ Erro: {str(e)}"
66
+ chat_history.append((prompt, error_msg))
67
+ return "", chat_history
68
+
69
+ # --- Interface --- #
70
+ with gr.Blocks(
71
+ theme=gr.themes.Soft(
72
+ primary_hue="blue",
73
+ neutral_hue="slate",
74
+ font=[gr.themes.GoogleFont("Inter")]
75
+ ),
76
+ css="""
77
+ .chatbot { font-family: 'Inter', sans-serif; min-height: 400px; }
78
+ .code { max-height: 500px; overflow-y: auto !important; }
79
+ """
80
+ ) as app:
81
+
82
+ gr.Markdown("# <center>🧑💻 Assistente de Programação Avançado</center>")
83
+
84
+ with gr.Row():
85
+ with gr.Column(scale=3):
86
+ language = gr.Dropdown(
87
+ choices=list(LANGUAGES.keys()),
88
+ value="python",
89
+ label="Linguagem de Programação"
90
+ )
91
+
92
+ chatbot = gr.Chatbot(
93
+ bubble_full_width=False,
94
+ avatar_images=("user.png", "ai.png"),
95
+ height=500
96
+ )
97
+
98
+ msg = gr.Textbox(
99
+ placeholder="Descreva o código que precisa (ex: 'função para calcular IMC')",
100
+ lines=3
101
+ )
102
+
103
+ with gr.Row():
104
+ submit_btn = gr.Button("Enviar", variant="primary")
105
+ clear_btn = gr.Button("Limpar")
106
+
107
+ with gr.Column(scale=2):
108
+ gr.Markdown("### 📚 Capacidades do Assistente:")
109
+ gr.Markdown("""
110
+ - Gera código em **Python, JavaScript, Java, C++, HTML, SQL**
111
+ - Suporta estruturas complexas (classes, funções, APIs)
112
+ - Documentação automática do código
113
+ - Sintaxe correta para cada linguagem
114
+ - Exemplos práticos e testáveis
115
+ """)
116
+
117
+ gr.Examples(
118
+ examples=[
119
+ ["Implemente uma linked list em Python", "python"],
120
+ ["Crie um componente React em JavaScript", "javascript"],
121
+ ["Classe para conexão MySQL em Java", "java"]
122
+ ],
123
+ inputs=[msg, language],
124
+ label="Clique para carregar exemplos"
125
+ )
126
+
127
+ # Eventos
128
+ msg.submit(generate_response, [msg, language, chatbot], [msg, chatbot])
129
+ submit_btn.click(generate_response, [msg, language, chatbot], [msg, chatbot])
130
+ clear_btn.click(lambda: None, None, chatbot, queue=False)
131
+
132
+ app.queue(concurrency_count=2)
133
+ app.launch(server_name="0.0.0.0", server_port=7860)