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()
|