Spaces:
Runtime error

File size: 1,288 Bytes
7c01156
 
 
 
29c97c1
5121de2
7c01156
 
 
9214350
a257342
9214350
 
 
 
1382e79
 
 
 
 
7c01156
a257342
7c01156
 
 
 
 
 
1076771
7c01156
 
 
 
 
 
 
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
import openai
import gradio as gr

# OpenAI API ํ‚ค ์„ค์ •
openai.api_key = 'sk-proj-bVrEIXCRUgwpPGg8b5AoT3BlbkFJUNwFDqrjhlvfeak799mL'

def get_medication_info(medication_name):
    try:
        # ChatGPT์— ์•ฝ์˜ ์ด๋ฆ„์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์š”์ฒญ
        response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo",  # ๋ชจ๋ธ์€ ํ•„์š”์— ๋”ฐ๋ผ ์ตœ์‹  ๋ฒ„์ „์œผ๋กœ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": f"์•ฝ์˜ ์ด๋ฆ„ '{medication_name}'์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”."}
            ],
            temperature=0.5,
            max_tokens=150,
            top_p=1.0,
            frequency_penalty=0.0,
            presence_penalty=0.0
        )
        return response['choices'][0]['message']['content'].strip()
    except Exception as e:
        return str(e)

# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
iface = gr.Interface(
    fn=get_medication_info,
    inputs=gr.Textbox(lines=2, placeholder="์•ฝ์˜ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”..."),
    outputs="text",
    title="์•ฝ ์ •๋ณด ๊ฒ€์ƒ‰๊ธฐ",
    description="์•ฝ์˜ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๋ฉด ChatGPT๋ฅผ ํ†ตํ•ด ์•ฝ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฒ€์ƒ‰ํ•ด ๋“œ๋ฆฝ๋‹ˆ๋‹ค."
)

# ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
iface.launch()