cl / app.py
springwater's picture
Create app.py
30849df verified
import gradio as gr
from transformers import pipeline
# Hugging Face λͺ¨λΈ μ €μž₯μ†Œμ—μ„œ λͺ¨λΈμ„ λ‹€μš΄λ‘œλ“œν•˜μ—¬ μ΄ˆκΈ°ν™”
generator = pipeline('text-generation', model='facebook/bart-base')
def generate_self_introduction(job, strength, weakness, major, experience):
# μž…λ ₯ ν‚€μ›Œλ“œ 처리
job = job.strip()
strength = [s.strip() for s in strength.split(',')]
weakness = [w.strip() for w in weakness.split(',')]
major = major.strip()
experience = [e.strip() for e in experience.split(',')]
# μžκΈ°μ†Œκ°œμ„œ 생성
intro = f'μ•ˆλ…•ν•˜μ„Έμš”, {job} 직무에 μ§€μ›ν•˜λŠ” [이름]μž…λ‹ˆλ‹€.\n'
intro += f'μ €λŠ” {major} 전곡 μΆœμ‹ μœΌλ‘œ {experience[0]} κ²½ν—˜μ΄ μžˆμŠ΅λ‹ˆλ‹€.\n'
intro += f'μ €μ˜ 성격 μž₯점은 {", ".join(strength)}μž…λ‹ˆλ‹€.\n'
intro += f'μ €μ˜ 성격 단점은 {", ".join(weakness)}μž…λ‹ˆλ‹€.\n'
intro += generator(job, max_length=1024, num_return_sequences=1)[0]['generated_text'][:500] # μ΅œλŒ€ 길이λ₯Ό 1024둜 μ œν•œν•˜κ³ , 500μžκΉŒμ§€λ§Œ 좜λ ₯
return intro
# Gradio μΈν„°νŽ˜μ΄μŠ€ 생성
iface = gr.Interface(
fn=generate_self_introduction,
inputs=[
gr.Textbox(label='μ·¨μ—…ν•  직무 이름'),
gr.Textbox(label='λ‚˜μ˜ 성격 μž₯점 (콀마둜 ꡬ뢄)'),
gr.Textbox(label='λ‚˜μ˜ 성격 단점 (콀마둜 ꡬ뢄)'),
gr.Textbox(label='전곡'),
gr.Textbox(label='λŒ€μ™Έν™œλ™ κ²½ν—˜ (콀마둜 ꡬ뢄)'),
],
outputs=gr.Textbox(label='μžκΈ°μ†Œκ°œμ„œ'),
title='μžκΈ°μ†Œκ°œμ„œ 생성 μ„œλΉ„μŠ€',
description='μ·¨μ—…ν•  직무 이름, λ‚˜μ˜ 성격 μž₯점, λ‚˜μ˜ 성격 단점, 전곡, λŒ€μ™Έν™œλ™ κ²½ν—˜μ„ μž…λ ₯ν•˜μ—¬ μžκΈ°μ†Œκ°œμ„œλ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.'
)
# Gradio μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ‹€ν–‰
iface.launch()