mian-coder / app.py
miiann's picture
Create app.py
399e120 verified
raw
history blame
797 Bytes
import gradio as gr
from transformers import pipeline
# Using a smaller, more stable model
model = pipeline(
"text-generation",
model="bigcode/tiny_starcoder_py", # Very small model for CPU
device="cpu"
)
def generate_code(prompt):
try:
response = model(
f"# Python Question\n{prompt}\n# Answer\n",
max_new_tokens=80,
temperature=0.2,
do_sample=False
)
return response[0]['generated_text'].split("# Answer\n")[-1]
except Exception as e:
return f"Error: {str(e)}"
demo = gr.Interface(
fn=generate_code,
inputs=gr.Textbox(lines=2, placeholder="Ask about Python..."),
outputs=gr.Code(language="python"),
title="Stable Coding Assistant",
allow_flagging="never"
)
demo.launch()