Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
|
4 |
API_URL = "https://api-inference.huggingface.co/models/bigcode/starcoder"
|
5 |
-
import os
|
6 |
headers = {"Authorization": f"Bearer {os.environ['HF_TOKEN']}"}
|
7 |
|
8 |
-
def
|
9 |
-
payload = {
|
|
|
|
|
|
|
|
|
10 |
response = requests.post(API_URL, headers=headers, json=payload)
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
demo = gr.Interface(fn=coder_bot, inputs="text", outputs="text")
|
18 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
import os
|
4 |
|
5 |
API_URL = "https://api-inference.huggingface.co/models/bigcode/starcoder"
|
|
|
6 |
headers = {"Authorization": f"Bearer {os.environ['HF_TOKEN']}"}
|
7 |
|
8 |
+
def generate_code(prompt):
|
9 |
+
payload = {
|
10 |
+
"inputs": prompt,
|
11 |
+
"parameters": {"max_new_tokens": 300}
|
12 |
+
}
|
13 |
+
|
14 |
response = requests.post(API_URL, headers=headers, json=payload)
|
15 |
+
|
16 |
+
try:
|
17 |
+
generated_text = response.json()[0]["generated_text"]
|
18 |
+
except Exception as e:
|
19 |
+
generated_text = f"Error: {e}\nRaw Response: {response.text}"
|
20 |
+
|
21 |
+
return generated_text
|
22 |
+
|
23 |
+
demo = gr.Interface(fn=generate_code, inputs="text", outputs="text", title="Super Coder Bot", description="Enter instructions in plain English. Get real, production-ready code.")
|
24 |
|
|
|
25 |
demo.launch()
|