ochyai commited on
Commit
bfaa6a6
0 Parent(s):

Duplicate from ochyai/aol

Browse files
Files changed (6) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. app.py +104 -0
  4. constraints.md +13 -0
  5. requirements.txt +2 -0
  6. template.md +23 -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: ochyai_food
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: ochyai/aol
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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="ochyAI recipe generator"
9
+ inputs_label="どんな料理か教えてくれれば,新しいレシピを考えます"
10
+ outputs_label="ochyAIが返信をします"
11
+ description="""
12
+ - ※入出力の文字数は最大1000文字程度までを目安に入力してください。解答に120秒くらいかかります.
13
+ """
14
+
15
+ article = """
16
+ """
17
+
18
+ load_dotenv()
19
+ openai.api_key = os.getenv('OPENAI_API_KEY')
20
+ MODEL = "gpt-4"
21
+
22
+ def get_filetext(filename, cache={}):
23
+ if filename in cache:
24
+ # キャッシュに保存されている場合は、キャッシュからファイル内容を取得する
25
+ return cache[filename]
26
+ else:
27
+ if not os.path.exists(filename):
28
+ raise ValueError(f"ファイル '{filename}' が見つかりませんでした")
29
+ with open(filename, "r") as f:
30
+ text = f.read()
31
+ # ファイル内容をキャッシュする
32
+ cache[filename] = text
33
+ return text
34
+
35
+ class OpenAI:
36
+
37
+ @classmethod
38
+ def chat_completion(cls, prompt, start_with=""):
39
+ constraints = get_filetext(filename = "constraints.md")
40
+ template = get_filetext(filename = "template.md")
41
+
42
+ # ChatCompletion APIに渡すデータを定義する
43
+ data = {
44
+ "model": "gpt-4",
45
+ "messages": [
46
+ {"role": "system", "content": constraints}
47
+ ,{"role": "system", "content": template}
48
+ ,{"role": "assistant", "content": "Sure!"}
49
+ ,{"role": "user", "content": prompt}
50
+ ,{"role": "assistant", "content": start_with}
51
+ ],
52
+ }
53
+
54
+ # ChatCompletion APIを呼び出す
55
+ response = requests.post(
56
+ "https://api.openai.com/v1/chat/completions",
57
+ headers={
58
+ "Content-Type": "application/json",
59
+ "Authorization": f"Bearer {openai.api_key}"
60
+ },
61
+ json=data
62
+ )
63
+
64
+ # ChatCompletion APIから返された結果を取得する
65
+ result = response.json()
66
+ print(result)
67
+ content = result["choices"][0]["message"]["content"].strip()
68
+ return content
69
+
70
+ class NajiminoAI:
71
+
72
+ @classmethod
73
+ def generate_emo_prompt(cls, user_message):
74
+ template = get_filetext(filename="template.md")
75
+ prompt = f"""
76
+ {user_message}
77
+ ---
78
+ 上記を元に、下記テンプレートを埋めてください。
79
+ ---
80
+ {template}
81
+ """
82
+ return prompt
83
+
84
+ @classmethod
85
+ def generate_emo(cls, user_message):
86
+ prompt = NajiminoAI.generate_emo_prompt(user_message);
87
+ start_with = ""
88
+ result = OpenAI.chat_completion(prompt=prompt, start_with=start_with)
89
+ return result
90
+
91
+ def main():
92
+ iface = gr.Interface(fn=NajiminoAI.generate_emo,
93
+ inputs=gr.Textbox(label=inputs_label),
94
+ outputs=gr.Textbox(label=outputs_label),
95
+ title=title,
96
+ description=description,
97
+ article=article,
98
+ allow_flagging='never'
99
+ )
100
+
101
+ iface.launch()
102
+
103
+ if __name__ == '__main__':
104
+ main()
constraints.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #constraints
2
+
3
+ ALOs(Food):
4
+ - Ingredients: Identify, Store, Measure, Types, Seasonality, Allergens, Freshness, Quantity
5
+ - Recipes: Follow, Create, Modify, Types, Cuisine, DietaryRestrictions, Complexity, ServingSize
6
+ - Cuisine: Appreciate, Discover, Compare, Regions, Traditions, PopularDishes, Authenticity, Popularity
7
+ - NutritionalValue: Calculate, Optimize, Balance, Macronutrients, Micronutrients, Calories, Healthiness, Satisfaction
8
+ - PreparationMethods: Master, Improve, Teach, Techniques, Tools, CookingTemperatures, Proficiency, Efficiency
9
+ - MealTypes: Plan, Organize, Pair, Breakfast, Lunch, Dinner, Snacks, Dessert, Variety, Enjoyment
10
+
11
+ Execute ALO(Food) to generate novel, state of the art completely new recipe, instruction for new food, possible voice from the people who ate new recipe, visual representation of dish by words for generative AI that includes photgraphic settings of key image of dish, according to user input food domains and cheracteristics. Generate details as far as you can by brainstorming to fullfill all parameters. Implement linguistic adjustments to prevent and rectify errors.
12
+
13
+ #templates
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ openai>=0.27.0
2
+ python-dotenv
template.md ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Title of New Recipe
2
+
3
+ Please write your title of new recipe Here.
4
+
5
+ ### Your New Recipe Here
6
+
7
+ Please write new recipe and brainstorm every point of new recipe to fill the details.
8
+
9
+ ### Your Instruction Here
10
+
11
+ Please write your instruction to cook the dish of new recipe and brainstorm every point of new recipe to fill the details.
12
+
13
+ ### Your Comment and Feelings, taste of new recipe
14
+
15
+ Please write review commnet of new recipe here and brainstorm every point of new recipe to fill the details.
16
+
17
+ ### Your Explanation to Blind Person
18
+
19
+ Please write review commnet of new recipe here to explain to the blind people more concretely in detail. Please brainstorm every point of new recipe to fill the details.
20
+
21
+ ### Prompt for Visual Expression
22
+
23
+ Please write prompt for visual expression in Generative AI for image the visual of the new recipe and brainstorm every point of new recipe to fill the details.