Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
|
|
|
| 3 |
import subprocess
|
| 4 |
|
| 5 |
# Load a code-generation model with support for multiple languages
|
|
@@ -23,18 +24,24 @@ def execute_code(code, language):
|
|
| 23 |
return str(e)
|
| 24 |
return "Code execution only supported for Python."
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# Create a Gradio interface with language selection and execution
|
| 27 |
iface = gr.Interface(
|
| 28 |
-
fn=
|
| 29 |
inputs=[
|
| 30 |
gr.Textbox(lines=5, placeholder="Describe your coding task..."),
|
| 31 |
gr.Dropdown(choices=["Python", "JavaScript", "Java"], label="Programming Language")
|
| 32 |
],
|
| 33 |
-
outputs=[gr.Code(), gr.Textbox(label="Execution Output")],
|
| 34 |
title="Multi-Language Text-to-Code AI",
|
| 35 |
description="Convert natural language descriptions into code in different programming languages! Run Python code directly in the app.",
|
| 36 |
theme="default",
|
| 37 |
-
allow_flagging="never"
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
# Launch the app
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
import subprocess
|
| 5 |
|
| 6 |
# Load a code-generation model with support for multiple languages
|
|
|
|
| 24 |
return str(e)
|
| 25 |
return "Code execution only supported for Python."
|
| 26 |
|
| 27 |
+
def generate_and_execute(description, language):
|
| 28 |
+
code = generate_code(description, language)
|
| 29 |
+
output = execute_code(code, language) if language == "Python" else "Execution not supported for this language."
|
| 30 |
+
return code, output
|
| 31 |
+
|
| 32 |
# Create a Gradio interface with language selection and execution
|
| 33 |
iface = gr.Interface(
|
| 34 |
+
fn=generate_and_execute,
|
| 35 |
inputs=[
|
| 36 |
gr.Textbox(lines=5, placeholder="Describe your coding task..."),
|
| 37 |
gr.Dropdown(choices=["Python", "JavaScript", "Java"], label="Programming Language")
|
| 38 |
],
|
| 39 |
+
outputs=[gr.Code(label="Generated Code"), gr.Textbox(label="Execution Output")],
|
| 40 |
title="Multi-Language Text-to-Code AI",
|
| 41 |
description="Convert natural language descriptions into code in different programming languages! Run Python code directly in the app.",
|
| 42 |
theme="default",
|
| 43 |
+
allow_flagging="never",
|
| 44 |
+
live=True
|
| 45 |
)
|
| 46 |
|
| 47 |
# Launch the app
|