Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -25,19 +25,30 @@ def generate_code(instructions, language, generation_type):
|
|
25 |
return f'Error {response.status_code}: {response.text}'
|
26 |
|
27 |
# Gradio interface components
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
#
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
41 |
|
42 |
# Launch the interface
|
43 |
-
|
|
|
25 |
return f'Error {response.status_code}: {response.text}'
|
26 |
|
27 |
# Gradio interface components
|
28 |
+
with gr.Blocks() as demo:
|
29 |
+
gr.Markdown("# Code Generator Interface\nGenerate code snippets using CodePal's Code Generator API.")
|
30 |
+
with gr.Row():
|
31 |
+
with gr.Column():
|
32 |
+
instructions_input = gr.Textbox(label='Function Description', placeholder='Describe the function to generate...')
|
33 |
+
language_input = gr.Dropdown(label='Programming Language', choices=['python', 'javascript', 'go', 'java', 'csharp'])
|
34 |
+
generation_type_input = gr.Radio(label='Generation Type', choices=['minimal', 'standard', 'documented'], value='standard')
|
35 |
+
generate_button = gr.Button(value='Generate Code')
|
36 |
+
clear_button = gr.Button(value='Clear')
|
37 |
+
error_output = gr.Textbox(label='Error Message', visible=False)
|
38 |
+
with gr.Column():
|
39 |
+
output_display = gr.Code(label='Generated Code')
|
40 |
|
41 |
+
# Example inputs
|
42 |
+
examples = [
|
43 |
+
["Function to add two numbers", "python", "standard"],
|
44 |
+
["Class definition for a linked list", "java", "documented"],
|
45 |
+
["Script to fetch data from an API", "javascript", "minimal"]
|
46 |
+
]
|
47 |
+
gr.Examples(examples=examples, inputs=[instructions_input, language_input, generation_type_input])
|
48 |
+
|
49 |
+
# Define button actions
|
50 |
+
generate_button.click(generate_code, inputs=[instructions_input, language_input, generation_type_input], outputs=[output_display, error_output])
|
51 |
+
clear_button.click(lambda: ("", "python", "standard", "", ""), outputs=[instructions_input, language_input, generation_type_input, output_display, error_output])
|
52 |
|
53 |
# Launch the interface
|
54 |
+
demo.launch()
|