File size: 740 Bytes
4415497
9970b1b
4415497
afbdf3f
9970b1b
4415497
afbdf3f
9970b1b
 
afbdf3f
4415497
afbdf3f
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import pipeline

# Load model (you can change this to your own)
generator = pipeline("text-generation", model="Salesforce/codegen-350M-mono")

# Function to generate code from prompt
def generate_code(prompt):
    result = generator(prompt, max_new_tokens=100)[0]["generated_text"]
    return result.strip()

# Gradio UI and API Interface
iface = gr.Interface(
    fn=generate_code,
    inputs=gr.Textbox(label="Enter prompt (e.g., Describe code)"),
    outputs=gr.Textbox(label="Generated Code"),
    title="Code Generator AI",
    description="This app generates code based on your prompt. You can use it from the browser or call it via API."
)

# Launch Space (UI + API mode enabled)
iface.launch()