Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
def get_completion(prompt, api_key, model="text-davinci-002"):
|
| 6 |
+
openai.api_key = api_key
|
| 7 |
+
response = openai.Completion.create(
|
| 8 |
+
engine=model,
|
| 9 |
+
prompt=prompt,
|
| 10 |
+
temperature=0,
|
| 11 |
+
max_tokens=1024,
|
| 12 |
+
)
|
| 13 |
+
return response.choices[0].text.strip()
|
| 14 |
+
|
| 15 |
+
def extract_colors(fact_sheet_chair, api_key):
|
| 16 |
+
prompt = f"""
|
| 17 |
+
List character following content:
|
| 18 |
+
1 - List 4 popular props
|
| 19 |
+
2 - List 4 popular accessories
|
| 20 |
+
3 - List 4 popular clothes
|
| 21 |
+
|
| 22 |
+
Use the following format:
|
| 23 |
+
props:<4 popular props>
|
| 24 |
+
accessories:<4 popular accessories>
|
| 25 |
+
clothes:<4 popular clothes>
|
| 26 |
+
|
| 27 |
+
character: {fact_sheet_chair}
|
| 28 |
+
"""
|
| 29 |
+
response = get_completion(prompt, api_key)
|
| 30 |
+
return response
|
| 31 |
+
|
| 32 |
+
fact_sheet_chair_input = gr.inputs.Textbox(label="character")
|
| 33 |
+
api_key_input = gr.inputs.Textbox(label="OpenAI API")
|
| 34 |
+
output_text = gr.outputs.Textbox(label="Output")
|
| 35 |
+
|
| 36 |
+
title = "Character design inspiration"
|
| 37 |
+
description = "basis info"
|
| 38 |
+
inputs = [fact_sheet_chair_input, api_key_input]
|
| 39 |
+
outputs = [output_text]
|
| 40 |
+
|
| 41 |
+
gr.Interface(fn=extract_colors, inputs=inputs, outputs=outputs, title=title, description=description).launch()
|