Spaces:
Runtime error
Runtime error
Commit
·
12d1370
1
Parent(s):
b4d9f8f
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
import requests
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
api_url = "https://api.textsynth.com"
|
7 |
+
api_key = os.environ["TEXTSYNTH_API_SECRET_KEY"]
|
8 |
+
api_engine = "gptneox_20B"
|
9 |
+
|
10 |
+
def completion(prompt,max_tokens,temperature,top_k,top_p):
|
11 |
+
response = requests.post(api_url + "/v1/engines/" + "gptneox_20B" + "/completions", headers = { "Authorization": "Bearer " + api_key }, json = { "prompt": prompt, "max_tokens": max_tokens ,"temperature": temperature,"top_k": top_k,"top_p": top_p })
|
12 |
+
resp = response.json()
|
13 |
+
if "text" in resp:
|
14 |
+
return prompt + resp["text"]
|
15 |
+
else:
|
16 |
+
print("ERROR", resp)
|
17 |
+
assert False
|
18 |
+
|
19 |
+
if len(sys.argv) <= 1:
|
20 |
+
sys.exit(1)
|
21 |
+
|
22 |
+
demo = gr.Interface(
|
23 |
+
fn=completion,
|
24 |
+
inputs=[
|
25 |
+
gr.inputs.Textbox(lines=10,placeholder='Write some code..'),
|
26 |
+
gr.inputs.Slider(10,200,10,100,'Max Tokens',False),
|
27 |
+
gr.inputs.Slider(0,1.0,0.1,1.0,'temperature',False),
|
28 |
+
gr.inputs.Slider(0,50,1,40,'top_k',True),
|
29 |
+
gr.inputs.Slider(0,1.0,0.1,0.9,'top_p',True)
|
30 |
+
],
|
31 |
+
outputs="text",
|
32 |
+
theme='dark-huggingface',
|
33 |
+
title='Solo-Coder',
|
34 |
+
description='Build by Ansh and ❤️',
|
35 |
+
allow_flagging=False,
|
36 |
+
|
37 |
+
)
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
demo.launch()1
|