Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,16 @@
|
|
| 1 |
-
import requests
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
def generate_code(prompt, max_tokens):
|
| 8 |
-
payload = {
|
| 9 |
-
"inputs": prompt,
|
| 10 |
-
"parameters": {
|
| 11 |
-
"max_new_tokens": max_tokens,
|
| 12 |
-
"temperature": 0.7,
|
| 13 |
-
"do_sample": True,
|
| 14 |
-
"top_p": 0.95
|
| 15 |
-
}
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
headers = {} # No token required
|
| 19 |
-
response = requests.post(API_URL, json=payload, headers=headers)
|
| 20 |
-
|
| 21 |
-
if response.status_code == 200:
|
| 22 |
-
result = response.json()
|
| 23 |
-
return result[0]["generated_text"]
|
| 24 |
-
else:
|
| 25 |
-
return f"⚠️ Error {response.status_code}: {response.text}"
|
| 26 |
-
|
| 27 |
-
# Gradio interface
|
| 28 |
interface = gr.Interface(
|
| 29 |
-
fn=
|
| 30 |
-
inputs=
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
outputs=gr.Textbox(lines=10, label="Generated Code"),
|
| 35 |
-
title="🧠 Code Generator (No Token Needed)",
|
| 36 |
-
description="Uses Hugging Face hosted SantaCoder model. No login or GPU required."
|
| 37 |
)
|
| 38 |
|
| 39 |
if __name__ == "__main__":
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
def to_print_line(text):
|
| 4 |
+
# Escape double quotes inside the text
|
| 5 |
+
escaped_text = text.replace('"', '\\"')
|
| 6 |
+
return f'print("{escaped_text}")'
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
interface = gr.Interface(
|
| 9 |
+
fn=to_print_line,
|
| 10 |
+
inputs=gr.Textbox(lines=2, label="Text to print"),
|
| 11 |
+
outputs=gr.Textbox(lines=2, label="Generated Python Code"),
|
| 12 |
+
title="🖨️ Simple Python Code Generator",
|
| 13 |
+
description="Turns your input text into a Python print statement."
|
|
|
|
|
|
|
|
|
|
| 14 |
)
|
| 15 |
|
| 16 |
if __name__ == "__main__":
|