File size: 728 Bytes
399e120
 
 
65dfcfb
399e120
 
65dfcfb
399e120
 
 
 
 
 
65dfcfb
399e120
65dfcfb
399e120
 
 
 
 
 
 
 
 
 
65dfcfb
399e120
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()