| import openai |
| import gradio as gr |
| import os |
|
|
| def get_completion(prompt, api_key, model="text-davinci-002"): |
| openai.api_key = api_key |
| response = openai.Completion.create( |
| engine=model, |
| prompt=prompt, |
| temperature=0, |
| max_tokens=1024, |
| ) |
| return response.choices[0].text.strip() |
|
|
| def extract_colors(fact_sheet_chair, api_key): |
| prompt = f""" |
| List character following content: |
| 1 - List 4 popular props |
| 2 - List 4 popular accessories |
| 3 - List 4 popular clothes |
| |
| Use the following format: |
| props:<4 popular props> |
| accessories:<4 popular accessories> |
| clothes:<4 popular clothes> |
| |
| character: {fact_sheet_chair} |
| """ |
| response = get_completion(prompt, api_key) |
| return response |
|
|
| fact_sheet_chair_input = gr.inputs.Textbox(label="character") |
| api_key_input = gr.inputs.Textbox(label="OpenAI API") |
| output_text = gr.outputs.Textbox(label="Output") |
|
|
| title = "Character design inspiration" |
| description = "basis info" |
| inputs = [fact_sheet_chair_input, api_key_input] |
| outputs = [output_text] |
|
|
| gr.Interface(fn=extract_colors, inputs=inputs, outputs=outputs, title=title, description=description).launch() |