Spaces:
Runtime error
Runtime error
Commit
·
c13e9af
0
Parent(s):
Duplicate from shigel/recipe
Browse files- .gitattributes +34 -0
- README.md +13 -0
- app.py +115 -0
- constraints.md +26 -0
- requirements.txt +2 -0
- template.md +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: 新レシピ考案AI(β)
|
| 3 |
+
emoji: 🌖
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: red
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 3.19.1
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
duplicated_from: shigel/recipe
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
+
import requests
|
| 4 |
+
import os
|
| 5 |
+
import fileinput
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
|
| 8 |
+
title="新レシピ考案AI(β)"
|
| 9 |
+
inputs_label="どんな斬新なレシピを考案したいですか?\n例) サバ、お好み焼き、洋風"
|
| 10 |
+
outputs_label="AIが斬新なレシピを考案してくれます。"
|
| 11 |
+
description="""
|
| 12 |
+
- 新レシピ考案AI(β)を使うと、AIが斬新なレシピを考案して1分程度で返信してくれます!
|
| 13 |
+
- ※入出力の文字数は最大1000文字程度までを目安に入力してください。
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
article = """
|
| 17 |
+
<center><a href="https://huggingface.co/spaces/shigel/aiemo?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a></center>
|
| 18 |
+
<h5>注意事項</h5>
|
| 19 |
+
<ul>
|
| 20 |
+
<li style="font-size: small;">当サービスでは、2023/3/1にリリースされたOpenAI社のChatGPT APIのgpt-3.5-turboを使用しております。</li>
|
| 21 |
+
<li style="font-size: small;">当サービスで生成されたコンテンツは、OpenAI が提供する人工知能によるものであり、当サービスやOpenAI がその正確性や信頼性を保証するものではありません。</li>
|
| 22 |
+
<li style="font-size: small;"><a href="https://platform.openai.com/docs/usage-policies">OpenAI の利用規約</a>に従い、データ保持しない方針です(ただし諸般の事情によっては変更する可能性はございます)。
|
| 23 |
+
<li style="font-size: small;">当サービスで生成されたコンテンツは事実確認をした上で、コンテンツ生成者およびコンテンツ利用者の責任において利用してください。</li>
|
| 24 |
+
<li style="font-size: small;">当サービスでの使用により発生したいかなる損害についても、当社は一切の責任を負いません。</li>
|
| 25 |
+
<li style="font-size: small;">当サービスはβ版のため、予告なくサービスを終了する場合がございます。</li>
|
| 26 |
+
</ul>
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
load_dotenv()
|
| 30 |
+
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 31 |
+
MODEL = "gpt-3.5-turbo"
|
| 32 |
+
|
| 33 |
+
def get_filetext(filename, cache={}):
|
| 34 |
+
if filename in cache:
|
| 35 |
+
# キャッシュに保存されている場合は、キャッシュからファイル内容を取得する
|
| 36 |
+
return cache[filename]
|
| 37 |
+
else:
|
| 38 |
+
if not os.path.exists(filename):
|
| 39 |
+
raise ValueError(f"ファイル '{filename}' が見つかりませんでした")
|
| 40 |
+
with open(filename, "r") as f:
|
| 41 |
+
text = f.read()
|
| 42 |
+
# ファイル内容をキャッシュする
|
| 43 |
+
cache[filename] = text
|
| 44 |
+
return text
|
| 45 |
+
|
| 46 |
+
class OpenAI:
|
| 47 |
+
|
| 48 |
+
@classmethod
|
| 49 |
+
def chat_completion(cls, prompt, start_with=""):
|
| 50 |
+
constraints = get_filetext(filename = "constraints.md")
|
| 51 |
+
template = get_filetext(filename = "template.md")
|
| 52 |
+
|
| 53 |
+
# ChatCompletion APIに渡すデータを定義する
|
| 54 |
+
data = {
|
| 55 |
+
"model": "gpt-3.5-turbo",
|
| 56 |
+
"messages": [
|
| 57 |
+
{"role": "system", "content": constraints}
|
| 58 |
+
,{"role": "system", "content": template}
|
| 59 |
+
,{"role": "assistant", "content": "Sure!"}
|
| 60 |
+
,{"role": "user", "content": prompt}
|
| 61 |
+
,{"role": "assistant", "content": start_with}
|
| 62 |
+
],
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
# ChatCompletion APIを呼び出す
|
| 66 |
+
response = requests.post(
|
| 67 |
+
"https://api.openai.com/v1/chat/completions",
|
| 68 |
+
headers={
|
| 69 |
+
"Content-Type": "application/json",
|
| 70 |
+
"Authorization": f"Bearer {openai.api_key}"
|
| 71 |
+
},
|
| 72 |
+
json=data
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
# ChatCompletion APIから返された結果を取得する
|
| 76 |
+
result = response.json()
|
| 77 |
+
print(result)
|
| 78 |
+
content = result["choices"][0]["message"]["content"].strip()
|
| 79 |
+
return content
|
| 80 |
+
|
| 81 |
+
class NajiminoAI:
|
| 82 |
+
|
| 83 |
+
@classmethod
|
| 84 |
+
def generate_emo_prompt(cls, user_message):
|
| 85 |
+
template = get_filetext(filename="template.md")
|
| 86 |
+
prompt = f"""
|
| 87 |
+
{user_message}
|
| 88 |
+
---
|
| 89 |
+
斬新なレシピを生成してください。
|
| 90 |
+
---
|
| 91 |
+
{template}
|
| 92 |
+
"""
|
| 93 |
+
return prompt
|
| 94 |
+
|
| 95 |
+
@classmethod
|
| 96 |
+
def generate_emo(cls, user_message):
|
| 97 |
+
prompt = NajiminoAI.generate_emo_prompt(user_message);
|
| 98 |
+
start_with = ""
|
| 99 |
+
result = OpenAI.chat_completion(prompt=prompt, start_with=start_with)
|
| 100 |
+
return result
|
| 101 |
+
|
| 102 |
+
def main():
|
| 103 |
+
iface = gr.Interface(fn=NajiminoAI.generate_emo,
|
| 104 |
+
inputs=gr.Textbox(label=inputs_label),
|
| 105 |
+
outputs=gr.Textbox(label=outputs_label),
|
| 106 |
+
title=title,
|
| 107 |
+
description=description,
|
| 108 |
+
article=article,
|
| 109 |
+
allow_flagging='never'
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
iface.launch()
|
| 113 |
+
|
| 114 |
+
if __name__ == '__main__':
|
| 115 |
+
main()
|
constraints.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
【オブジェクト: 料理レシピ】
|
| 2 |
+
|
| 3 |
+
【サブオブジェクト】
|
| 4 |
+
- 材料: 新鮮な野菜、スパイス、調味料、お肉または魚、その他必要なもの
|
| 5 |
+
- 能力: 料理の技術、創造力、美味しさに関する知識、試行錯誤能力
|
| 6 |
+
- 状態認識: 食材の状態、食材を調理する際の温度の状態、調味料の量
|
| 7 |
+
|
| 8 |
+
【制約】
|
| 9 |
+
- 料理レシピは新しくて、他に似たようなレシピが存在しない。
|
| 10 |
+
- 食材は新鮮である必要がある。
|
| 11 |
+
- 料理の過程で、一定の順序と技術が必要であり、素材や火力の管理が必要である。
|
| 12 |
+
- 料理の味付けや素材の使い方について、独自のアイデアと創造的な発想が求められる。
|
| 13 |
+
|
| 14 |
+
【初期状態】
|
| 15 |
+
- 材料が揃っている
|
| 16 |
+
- 料理レシピが決まっている
|
| 17 |
+
- 料理レシピの作成者が、料理を作るための技能、知識、創造力がある
|
| 18 |
+
|
| 19 |
+
【状態変化】
|
| 20 |
+
- 料理レシピの内容に基づき、材料を調理する。
|
| 21 |
+
- 料理レシピに合わせて、一定の手順に従って材料を加熱し、調味料を加える。
|
| 22 |
+
- 料理の味や色、食感などを確認しながら、試行錯誤を重ね、熟成させる。
|
| 23 |
+
- 最終的に、美味しい一皿が完成したと認識できる。
|
| 24 |
+
|
| 25 |
+
【管理オブジェクト】
|
| 26 |
+
- 料理レシピを作成する人、または料理人。
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
openai>=0.27.0
|
| 2 |
+
python-dotenv
|
template.md
ADDED
|
File without changes
|