File size: 1,300 Bytes
ba9865c 0546ebe ba9865c 0546ebe f3fa3c9 ba9865c 1dfcb9d ba9865c 1dfcb9d d7def05 ba9865c c58620a 9b5a84e ba9865c 9b5a84e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import requests
import json
import gradio as gr
import os
REST_API_KEY = os.environ.get("REST_API_KEY")
def kogpt_api(prompt, max_tokens = 32, temperature = 1.0, top_p = 1.0, n = 1):
r = requests.post(
url='https://api.kakaobrain.com/v1/inference/kogpt/generation',
headers = {
'Authorization': 'KakaoAK ' + REST_API_KEY,
'Content-Type': 'application/json'
},
json = {
'prompt': prompt,
'max_tokens': max_tokens,
'temperature': temperature,
'top_p': top_p,
'n': n
}
)
response = json.loads(r.content)
return response
def greet(prompt, max_tokens, temperature, top_p, n):
response = kogpt_api(
prompt = prompt,
max_tokens = int(max_tokens),
temperature = float(temperature),
top_p = float(top_p),
n = int(n)
)
return response['generations'][0]['text']
iface = gr.Interface(
fn=greet,
inputs=[
gr.Textbox(lines=2, placeholder="Input Prompt Here...", label="textbox"),
gr.Number(value=32),
gr.Slider(0.1, 1.0, step=0.1, value=0.5),
gr.Slider(0.1, 1.0, step=0.1, value=0.5),
gr.Slider(1, 16, step=0.1, value=1)],
outputs=["text"]
)
iface.launch() |