Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Stable configuration for CPU | |
model = pipeline( | |
"text-generation", | |
model="bigcode/tiny_starcoder_py", | |
device="cpu" | |
) | |
def generate_code(prompt): | |
try: | |
response = model( | |
f"# Question\n{prompt}\n# Answer\n", | |
max_new_tokens=80, | |
temperature=0.3, | |
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" | |
) | |
demo.launch() |