Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import yaml | |
| import json | |
| import os | |
| from openai import OpenAI | |
| from llm_functions import generate_question_recommendation, parse_question_recommendation | |
| # OpenAI ํด๋ผ์ด์ธํธ ์ด๊ธฐํ | |
| client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) | |
| # ํ๋กฌํํธ ๋ก๋ | |
| def load_prompts(): | |
| with open('prompt.yaml', 'r', encoding='utf-8') as file: | |
| return yaml.safe_load(file) | |
| prompts = load_prompts() | |
| def recommend_question(job_title, company_name, experience_level): | |
| """๋ฉด์ ์ง๋ฌธ์ ์ถ์ฒํ๋ ํจ์""" | |
| try: | |
| # LLM ํจ์ ํธ์ถ | |
| result = generate_question_recommendation( | |
| client=client, | |
| prompts=prompts, | |
| job_title=job_title, | |
| company_name=company_name, | |
| experience_level=experience_level | |
| ) | |
| # ๊ฒฐ๊ณผ ํ์ฑ | |
| parsed_result = parse_question_recommendation(result) | |
| if parsed_result and 'recommended_question' in parsed_result: | |
| return parsed_result['recommended_question'] | |
| else: | |
| return "์ง๋ฌธ ์์ฑ์ ์คํจํ์ต๋๋ค. ๋ค์ ์๋ํด์ฃผ์ธ์." | |
| except Exception as e: | |
| return f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}" | |
| # ์์ ๋ฒํผ ํจ์๋ค | |
| def example_1(): | |
| return "๋ฐฑ์๋ ๊ฐ๋ฐ", "ํ ์ค (๋น๋ฐ๋ฆฌํผ๋ธ๋ฆฌ์นด)", "์ ์ " | |
| def example_2(): | |
| return "์ํ๋ง์ผํ ", "CJ์ ์ผ์ ๋น", "๊ฒฝ๋ ฅ" | |
| def example_3(): | |
| return "A&R", "ํ์ด๋ธ", "์ธํด" | |
| def example_4(): | |
| return "๊ฒฝ์๊ธฐํ", "ํ๋๊ฑด์ค", "์ ์ " | |
| def example_5(): | |
| return "ํด์ธ์์ ", "์ผ์ฑ์ ์", "๊ฒฝ๋ ฅ" | |
| # Gradio ์ธํฐํ์ด์ค ์์ฑ | |
| with gr.Blocks( | |
| title="๋ฉด์ ์ง๋ฌธ ์ถ์ฒ", | |
| theme=gr.themes.Soft( | |
| primary_hue="purple", | |
| secondary_hue="pink", | |
| neutral_hue="gray" | |
| ), | |
| css=""" | |
| .main-container { | |
| max-width: 900px; | |
| margin: 0 auto; | |
| padding: 20px; | |
| } | |
| .header { | |
| text-align: center; | |
| margin-bottom: 30px; | |
| padding: 20px; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| border-radius: 15px; | |
| color: white; | |
| } | |
| .input-section { | |
| background: white; | |
| padding: 25px; | |
| border-radius: 15px; | |
| box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | |
| margin-bottom: 20px; | |
| } | |
| .result-section { | |
| background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); | |
| padding: 25px; | |
| border-radius: 15px; | |
| color: white; | |
| margin-top: 20px; | |
| } | |
| .example-buttons { | |
| display: flex; | |
| flex-wrap: wrap; | |
| gap: 10px; | |
| margin-top: 15px; | |
| justify-content: center; | |
| } | |
| .example-btn { | |
| background: linear-gradient(45deg, #667eea, #764ba2); | |
| border: none; | |
| color: white; | |
| padding: 8px 16px; | |
| border-radius: 20px; | |
| font-size: 12px; | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| } | |
| .example-btn:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 4px 8px rgba(0,0,0,0.2); | |
| } | |
| """ | |
| ) as demo: | |
| with gr.Column(elem_classes="main-container"): | |
| # ํค๋ | |
| gr.HTML(""" | |
| <div class="header"> | |
| <h1>๐ฏ ๋ฉด์ ์ง๋ฌธ ์ถ์ฒ</h1> | |
| <p>์ง๋ฌด, ํ์ฌ๋ช , ๊ฒฝ๋ ฅ ์์ค์ ์ ๋ ฅํ๋ฉด ๋ง์ถคํ ๋ฉด์ ์ง๋ฌธ์ ์ถ์ฒํด๋๋ฆฝ๋๋ค</p> | |
| </div> | |
| """) | |
| with gr.Column(elem_classes="input-section"): | |
| gr.HTML("<h3>๐ ์ ๋ณด ์ ๋ ฅ</h3>") | |
| job_title = gr.Textbox( | |
| label="์ง๋ฌด", | |
| placeholder="์: ๋ฐฑ์๋ ๊ฐ๋ฐ, ๋ง์ผํ , ๊ธฐํ ๋ฑ", | |
| lines=1 | |
| ) | |
| company_name = gr.Textbox( | |
| label="ํ์ฌ๋ช ", | |
| placeholder="์: ํ ์ค, ์ผ์ฑ์ ์, ๋ค์ด๋ฒ ๋ฑ", | |
| lines=1 | |
| ) | |
| experience_level = gr.Dropdown( | |
| label="๊ฒฝ๋ ฅ ์์ค", | |
| choices=["์ ์ ", "๊ฒฝ๋ ฅ", "์ธํด", "๊ธฐํ"], | |
| value="์ ์ " | |
| ) | |
| # ์์ ๋ฒํผ๋ค | |
| gr.HTML("<h4>๐ก ์์๋ก ์์ํ๊ธฐ</h4>") | |
| with gr.Row(): | |
| ex1_btn = gr.Button("ํ ์ค ๋ฐฑ์๋ ์ ์ ", size="sm", variant="secondary") | |
| ex2_btn = gr.Button("CJ์ ์ผ์ ๋น ๋ง์ผํ ๊ฒฝ๋ ฅ", size="sm", variant="secondary") | |
| ex3_btn = gr.Button("ํ์ด๋ธ A&R ์ธํด", size="sm", variant="secondary") | |
| with gr.Row(): | |
| ex4_btn = gr.Button("ํ๋๊ฑด์ค ๊ฒฝ์๊ธฐํ ์ ์ ", size="sm", variant="secondary") | |
| ex5_btn = gr.Button("์ผ์ฑ์ ์ ํด์ธ์์ ๊ฒฝ๋ ฅ", size="sm", variant="secondary") | |
| submit_btn = gr.Button("๐ฏ ๋ฉด์ ์ง๋ฌธ ์ถ์ฒ๋ฐ๊ธฐ", variant="primary", size="lg") | |
| # ๊ฒฐ๊ณผ ์ถ๋ ฅ | |
| with gr.Column(elem_classes="result-section"): | |
| gr.HTML("<h3>๐ฌ ์ถ์ฒ ๋ฉด์ ์ง๋ฌธ</h3>") | |
| result_output = gr.Textbox( | |
| label="", | |
| placeholder="์ ์ ๋ณด๋ฅผ ์ ๋ ฅํ๊ณ '๋ฉด์ ์ง๋ฌธ ์ถ์ฒ๋ฐ๊ธฐ' ๋ฒํผ์ ํด๋ฆญํ์ธ์.", | |
| lines=5, | |
| show_label=False, | |
| interactive=False | |
| ) | |
| # ์ด๋ฒคํธ ํธ๋ค๋ฌ | |
| submit_btn.click( | |
| fn=recommend_question, | |
| inputs=[job_title, company_name, experience_level], | |
| outputs=result_output | |
| ) | |
| # ์์ ๋ฒํผ ์ด๋ฒคํธ | |
| ex1_btn.click(fn=example_1, outputs=[job_title, company_name, experience_level]) | |
| ex2_btn.click(fn=example_2, outputs=[job_title, company_name, experience_level]) | |
| ex3_btn.click(fn=example_3, outputs=[job_title, company_name, experience_level]) | |
| ex4_btn.click(fn=example_4, outputs=[job_title, company_name, experience_level]) | |
| ex5_btn.click(fn=example_5, outputs=[job_title, company_name, experience_level]) | |
| if __name__ == "__main__": | |
| demo.launch( | |
| # server_port=7864, | |
| share=True, | |
| show_error=True | |
| ) |