Smartpower001 commited on
Commit
0c83302
·
verified ·
1 Parent(s): b4a9077

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
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 coder_bot(instruction):
9
- payload = {"inputs": instruction}
 
 
 
 
10
  response = requests.post(API_URL, headers=headers, json=payload)
11
- result = response.json()
12
- if isinstance(result, list) and "generated_text" in result[0]:
13
- return result[0]["generated_text"]
14
- else:
15
- return "Something went wrong or model is loading. Please try again in a few seconds."
 
 
 
 
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()