Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
generator = pipeline("text-generation", model="Salesforce/codegen-350M-mono")
|
| 6 |
|
|
|
|
| 7 |
def generate_code(prompt):
|
| 8 |
result = generator(prompt, max_new_tokens=100)[0]["generated_text"]
|
| 9 |
-
return result
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load model (you can change this to your own)
|
| 5 |
generator = pipeline("text-generation", model="Salesforce/codegen-350M-mono")
|
| 6 |
|
| 7 |
+
# Function to generate code from prompt
|
| 8 |
def generate_code(prompt):
|
| 9 |
result = generator(prompt, max_new_tokens=100)[0]["generated_text"]
|
| 10 |
+
return result.strip()
|
| 11 |
|
| 12 |
+
# Gradio UI and API Interface
|
| 13 |
+
iface = gr.Interface(
|
| 14 |
+
fn=generate_code,
|
| 15 |
+
inputs=gr.Textbox(label="Enter prompt (e.g., Describe code)"),
|
| 16 |
+
outputs=gr.Textbox(label="Generated Code"),
|
| 17 |
+
title="Code Generator AI",
|
| 18 |
+
description="This app generates code based on your prompt. You can use it from the browser or call it via API."
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Launch Space (UI + API mode enabled)
|
| 22 |
+
iface.launch()
|