File size: 2,669 Bytes
c35600d
 
91c5fb7
c35600d
00bec19
8b1f0bb
91c5fb7
71d06ad
8b1f0bb
00bec19
 
 
 
 
8b1f0bb
b38c52a
 
 
 
 
91c5fb7
8b1f0bb
c35600d
91c5fb7
 
 
 
 
 
 
7204704
91c5fb7
9754c11
91c5fb7
9754c11
 
91c5fb7
 
9754c11
91c5fb7
 
 
 
00bec19
 
 
 
 
 
9754c11
00bec19
91c5fb7
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
49
50
51
52
import gradio as gr
import requests
import json

API_URL = "https://api.openai.com/v1/chat/completions"

def predict(inputs, top_p, temperature, openai_api_key):
    narration_prompt = f"๋™์˜์ƒ์— ์‚ฌ์šฉํ•  ์ „๋ฌธ์ ์ธ ๋‚˜๋ ˆ์ด์…˜์„ ์ž‘์„ฑํ•˜๋ผ. ๋ฐ˜๋“œ์‹œ ํ•œ๊ธ€๋กœ ์ž‘์„ฑํ• ๊ฒƒ. ์ผ์ฒด์˜ ์ง€๋ฌธ์ด๋‚˜ ์ง€์‹œ, ๋ฐฐ๊ฒฝ ์„ค๋ช… ๋“ฑ์„ ๋…ธ์ถœ ํ•˜๊ฑฐ๋‚˜ ์ถœ๋ ฅํ•˜์ง€ ๋ง๊ณ  ์ˆœ์ˆ˜ํ•œ ๋‚˜๋ ˆ์ด์…˜๋งŒ 2์ค„์”ฉ ๋ฌถ์–ด์„œ ์ตœ๋Œ€ 10์ค„ ์ด๋‚ด๋กœ ์ถœ๋ ฅ๋ ฅ. ์ž…๋ ฅ: '{inputs}'"

    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {openai_api_key}"
    }

    payload = {
        "model": "gpt-4-1106-preview",
        "messages": [{"role": "system", "content": narration_prompt}],
        "temperature": temperature,
        "top_p": top_p,
        "n": 1,
        "max_tokens": 1000
    }

    response = requests.post(API_URL, headers=headers, json=payload)
    if response.status_code == 200:
        response_data = response.json()
        generated_text = response_data['choices'][0]['message']['content']
        return generated_text
    else:
        return "Error: Unable to generate response."

with gr.Blocks() as demo:
    gr.Markdown("<h1 align='center'>ํ˜œ์ž ์Šคํฌ๋ฆฝํŠธ</h1>")
    with gr.Row():
        openai_api_key = gr.Textbox(type='password', label="Enter your OpenAI API key here")
        inputs = gr.Textbox(placeholder="์—ฌ๊ธฐ์— ์ž…๋ ฅํ•˜์„ธ์š”.", label="๋‚˜๋ ˆ์ด์…˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์‹ถ์€ ์ฃผ์ œ์–ด๋‚˜ ๋ฌธ์žฅ์„ ์ž…๋ ฅํ•˜์„ธ์š”.")
        top_p = gr.Slider(minimum=0, maximum=1.0, value=1.0, step=0.05, label="Top-p (nucleus sampling)")
        temperature = gr.Slider(minimum=0, maximum=5.0, value=1.0, step=0.1, label="Temperature")
    output = gr.Textbox(label="Generated Script", readonly=True)
    submit_button = gr.Button("Generate")
    submit_button.click(fn=predict, inputs=[inputs, top_p, temperature, openai_api_key], outputs=output)

    examples = gr.Examples(examples=[
            ["์ƒํ’ˆ ์„ค๋ช…:์ƒˆ๋กœ ์ถœ์‹œ๋œ 'ํ† ๋ฆฌ' ๋ฆฝ๋ฐค์€ FDA ์Šน์ธ, ์ตœ๊ณ ์˜ ๋ณด์Šต๋ ฅ, ๊ตฌ๋งค์ง€์ˆ˜ 1์œ„"],
            ["๋ธŒ๋žœ๋”ฉ: 'ํ† ๋ฆฌ'๋ฆฝ๋ฐค์€ 20๋Œ€ ์—ฌ์„ฑ์—๊ฒŒ ์–ดํ•„ํ•  ๋ธŒ๋žœ๋”ฉ์ด ํ•„์š”ํ•ด"],
            ["๊ด‘๊ณ : ์„ค๋‚  ๋ถ€๋ชจ๋‹˜๊ณผ ์นœ์ง€ ์„ ๋ฌผ์€ ๋ฒ•์„ฑํฌ ๋ณด๋ฆฌ๊ตด๋น„ '๋ฒ•์„ฑ๊ตด๋น„'๊ฐ€ ์ตœ๊ณ ๋ž๋‹ˆ๋‹ค."],
            ["์ •๋ณด ๊ณต์œ : ๋น„ํƒ€๋ฏผC ๊ณผ๋‹ค ๋ณต์šฉ์€ ๊ฑด๊ฐ•์— ์˜คํžˆ๋ ค ํ•ด๋กญ๋‹ค."],
            ["ํ™๋ณด: 'OpenAI'๋Š” '์ฑ—GPT'์˜ ๋งž์ถค GPT '์Šคํ† ์–ด'๋ฅผ ์˜คํ”ˆํ•˜์˜€๋‹ค."],
            ["์ธ์‚ฌ: '์• ํ”Œ ๋ฒ•์ธ'์˜ ๊ณ ๊ฐ๊ณผ ์ž„์ง์›์„ ์œ„ํ•œ ์ง„์ทจ์ ์ธ 2024๋…„ ์‹ ๋…„ ์ธ์‚ฌ"]
            ], inputs=[inputs], fn=predict, outputs=output)

demo.launch()