Spaces:
Runtime error
Runtime error
import os | |
import gradio as gr | |
import openai | |
class OpenAIUtils: | |
def use_openai_chatgpt_base(cls, prompt): | |
""" | |
Use OpenAI's GPT-3 model, Davinci, to generate text based on the given prompt | |
""" | |
openai.api_key = os.getenv('OPENAI_API_KEY') | |
print("prompt") | |
# print(prompt) | |
try: | |
res = openai.ChatCompletion.create( | |
# res = openai.Completion.create( | |
model="gpt-3.5-turbo", | |
# model="gpt-4", | |
messages=[ | |
{"role": "system", "content": "あなたは企業の採用担当です"}, | |
# {"role": "user", "content": prompt}, | |
{"role": "user", "content": f"{prompt}"}, | |
] | |
) | |
string = res.choices[0]['message']['content'] | |
except openai.error.InvalidRequestError as e: | |
print(f"Error: {e}") | |
return None | |
return string | |
def use_openai_davinci_base(cls, prompt): | |
""" | |
Use OpenAI's GPT-3 model, Davinci, to generate text based on the given prompt | |
""" | |
openai.api_key = os.getenv('OPENAI_API_KEY') | |
try: | |
res = openai.Completion.create( | |
model="text-davinci-003", | |
prompt=prompt, | |
max_tokens=1024, | |
temperature=0.5 | |
) | |
string = res.choices[0].text | |
except openai.error.InvalidRequestError as e: | |
print(f"Error: {e}") | |
return None | |
return string | |
class CalqOffer: | |
def generate_reply_mail_prompt(cls, offer, company, depart): | |
prompt = f""" | |
{offer} | |
上記の内容をもとにして以下を必須項目として、求人票を作成してください(1000文字程度)。 | |
【法人名】:{company} | |
【部門】:{depart} | |
【求人票のタイトル案】 | |
[落ち着いたタイトル案(3つ提案して)] | |
[ポップなタイトル案(3つ提案して)] | |
【仕事内容】 | |
【必要なスキル・経験(箇条書き)】 | |
【歓迎するスキル・経験(箇条書き)】 | |
【給与】 | |
【勤務地】 | |
【雇用形態】 | |
【待遇】 | |
""" | |
# print(prompt) | |
# return OpenAIUtils.use_openai_davinci_base(prompt) | |
return OpenAIUtils.use_openai_chatgpt_base(prompt) | |
def post_process_mail_reply(offer_reply): | |
remove_list = ["(箇条書き)"] | |
for item in remove_list: | |
offer_reply = offer_reply.replace(item, "") | |
offer_reply = offer_reply.replace("(3つ提案して)", "(3つ)") | |
return offer_reply | |
def greet(offer, company, depart): | |
offer_reply = CalqOffer.generate_reply_mail_prompt(offer, company, depart) | |
# print(offer_reply) | |
offer_reply = CalqOffer.post_process_mail_reply(offer_reply) | |
print(offer_reply) | |
return offer_reply | |
input_offer = gr.Textbox(label="採用したい人材の情報を列挙してください(例:マネージャー、年収500万円、東京)") | |
input_company = gr.Textbox(label="あなたの会社名(オプション)") | |
input_depart = gr.Textbox(label="部門(オプション)") | |
output_offer = gr.Textbox(label="求人票提案文章(最大1分ほどお待ちください)") | |
description=""" | |
""" | |
article = """ | |
""" | |
iface = gr.Interface( | |
fn=greet, | |
inputs=[input_offer, input_company, input_depart], | |
outputs=[output_offer], | |
title="", | |
description=description, | |
article=article | |
) | |
iface.launch() | |