Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,18 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def coder_bot(instruction):
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|