Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Using a smaller, more stable model
|
| 5 |
+
model = pipeline(
|
| 6 |
+
"text-generation",
|
| 7 |
+
model="bigcode/tiny_starcoder_py", # Very small model for CPU
|
| 8 |
+
device="cpu"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
def generate_code(prompt):
|
| 12 |
+
try:
|
| 13 |
+
response = model(
|
| 14 |
+
f"# Python Question\n{prompt}\n# Answer\n",
|
| 15 |
+
max_new_tokens=80,
|
| 16 |
+
temperature=0.2,
|
| 17 |
+
do_sample=False
|
| 18 |
+
)
|
| 19 |
+
return response[0]['generated_text'].split("# Answer\n")[-1]
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return f"Error: {str(e)}"
|
| 22 |
+
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=generate_code,
|
| 25 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask about Python..."),
|
| 26 |
+
outputs=gr.Code(language="python"),
|
| 27 |
+
title="Stable Coding Assistant",
|
| 28 |
+
allow_flagging="never"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
demo.launch()
|