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