Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load a code-generation model (you can replace this with a better one if needed)
|
| 5 |
+
code_generator = pipeline("text2text-generation", model="bigcode/t5-code-generation")
|
| 6 |
+
|
| 7 |
+
def generate_code(description):
|
| 8 |
+
response = code_generator(description, max_length=200)[0]['generated_text']
|
| 9 |
+
return response
|
| 10 |
+
|
| 11 |
+
# Create a Gradio interface
|
| 12 |
+
iface = gr.Interface(
|
| 13 |
+
fn=generate_code,
|
| 14 |
+
inputs=gr.Textbox(lines=5, placeholder="Enter your task description here..."),
|
| 15 |
+
outputs=gr.Code(),
|
| 16 |
+
title="Text-to-Code Generator",
|
| 17 |
+
description="Convert natural language coding tasks into Python code!"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# Launch the app
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
iface.launch()
|