S-Dreamer commited on
Commit
4d58d83
·
verified ·
1 Parent(s): 67c516c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -13
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
- instructions_input = gr.Textbox(label='Function Description', placeholder='Describe the function to generate...')
29
- language_input = gr.Dropdown(label='Programming Language', choices=['python', 'javascript', 'go', 'java', 'csharp'])
30
- generation_type_input = gr.Radio(label='Generation Type', choices=['minimal', 'standard', 'documented'], value='standard')
31
- output_display = gr.Code(label='Generated Code')
 
 
 
 
 
 
 
 
32
 
33
- # Create Gradio interface
34
- interface = gr.Interface(
35
- fn=generate_code,
36
- inputs=[instructions_input, language_input, generation_type_input],
37
- outputs=output_display,
38
- title='Code Generator Interface',
39
- description='Generate code snippets using CodePal\'s Code Generator API.'
40
- )
 
 
 
41
 
42
  # Launch the interface
43
- interface.launch()
 
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()