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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -1,7 +1,18 @@
1
  import gradio as gr
 
 
 
 
 
2
 
3
  def coder_bot(instruction):
4
- return "Your AI Coder Bot received: " + instruction + "\n(Real code generation coming in next step!)"
 
 
 
 
 
 
5
 
6
  demo = gr.Interface(fn=coder_bot, inputs="text", outputs="text")
7
  demo.launch()
 
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()