Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
def kogpt_api(prompt, max_tokens = 1, temperature = 1.0, top_p = 1.0, n = 1):
|
| 6 |
+
r = requests.post(
|
| 7 |
+
url='https://api.kakaobrain.com/v1/inference/kogpt/generation',
|
| 8 |
+
headers = {
|
| 9 |
+
'Authorization': 'KakaoAK ' + REST_API_KEY,
|
| 10 |
+
'Content-Type': 'application/json'
|
| 11 |
+
},
|
| 12 |
+
json = {
|
| 13 |
+
'prompt': prompt,
|
| 14 |
+
'max_tokens': max_tokens,
|
| 15 |
+
'temperature': temperature,
|
| 16 |
+
'top_p': top_p,
|
| 17 |
+
'n': n
|
| 18 |
+
}
|
| 19 |
+
)
|
| 20 |
+
# 응답 JSON 형식으로 변환
|
| 21 |
+
response = json.loads(r.content)
|
| 22 |
+
return response
|
| 23 |
+
|
| 24 |
+
def greet(apikey, prompt, max_tokens, temperature, top_p, n):
|
| 25 |
+
response = kogpt_api(
|
| 26 |
+
prompt = prompt,
|
| 27 |
+
max_tokens = int(max_tokens),
|
| 28 |
+
temperature = float(temperature),
|
| 29 |
+
top_p = float(top_p),
|
| 30 |
+
n = int(n)
|
| 31 |
+
)
|
| 32 |
+
return response['generations'][0]['text']
|
| 33 |
+
|
| 34 |
+
iface = gr.Interface(
|
| 35 |
+
fn=greet,
|
| 36 |
+
inputs=[
|
| 37 |
+
gr.Textbox(),
|
| 38 |
+
gr.Textbox(lines=2, placeholder="Input Prompt Here..."),
|
| 39 |
+
"number",
|
| 40 |
+
gr.Slider(0.1, 1.0, step=0.1),
|
| 41 |
+
gr.Slider(0.1, 1.0, step=0.1),
|
| 42 |
+
gr.Slider(1, 16)],
|
| 43 |
+
outputs=["text"]
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
iface.launch()
|