momosuke-san commited on
Commit
e015f1b
1 Parent(s): 1f786d3

fix: app.py and requirements.txt

Browse files
Files changed (2) hide show
  1. app.py +24 -2
  2. requirements.txt +2 -1
app.py CHANGED
@@ -4,10 +4,15 @@ 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
  """
@@ -17,6 +22,11 @@ article = """
17
 
18
  load_dotenv()
19
  openai.api_key = os.getenv('OPENAI_API_KEY')
 
 
 
 
 
20
  MODEL = "gpt-4"
21
 
22
  def get_filetext(filename, cache={}):
@@ -65,8 +75,20 @@ class OpenAI:
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
@@ -91,7 +113,7 @@ class NajiminoAI:
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,
 
4
  import os
5
  import fileinput
6
  from dotenv import load_dotenv
7
+ import io
8
+ from PIL import Image
9
+ from stability_sdk import client
10
+ import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation
11
 
12
  title="ochyAI recipe generator"
13
  inputs_label="どんな料理か教えてくれれば,新しいレシピを考えます"
14
  outputs_label="ochyAIが返信をします"
15
+ visual_outputs_label="料理のイメージ"
16
  description="""
17
  - ※入出力の文字数は最大1000文字程度までを目安に入力してください。解答に120秒くらいかかります.
18
  """
 
22
 
23
  load_dotenv()
24
  openai.api_key = os.getenv('OPENAI_API_KEY')
25
+ os.environ['STABILITY_HOST'] = 'grpc.stability.ai:443'
26
+ stability_api = client.StabilityInference(
27
+ key=os.getenv('STABILITY_KEY'),
28
+ verbose=True,
29
+ )
30
  MODEL = "gpt-4"
31
 
32
  def get_filetext(filename, cache={}):
 
75
  result = response.json()
76
  print(result)
77
  content = result["choices"][0]["message"]["content"].strip()
78
+ visualize_prompt = content.split("### Prompt for Visual Expression\n\n")[1]
79
 
80
+ answers = stability_api.generate(
81
+ prompt=visualize_prompt,
82
+ )
83
+
84
+ for resp in answers:
85
+ for artifact in resp.artifacts:
86
+ if artifact.finish_reason == generation.FILTER:
87
+ print("NSFW")
88
+ if artifact.type == generation.ARTIFACT_IMAGE:
89
+ img = Image.open(io.BytesIO(artifact.binary))
90
+ return [content, img]
91
+
92
  class NajiminoAI:
93
 
94
  @classmethod
 
113
  def main():
114
  iface = gr.Interface(fn=NajiminoAI.generate_emo,
115
  inputs=gr.Textbox(label=inputs_label),
116
+ outputs=[gr.Textbox(label=inputs_label), gr.Image(label=visual_outputs_label)],
117
  title=title,
118
  description=description,
119
  article=article,
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  openai>=0.27.0
2
- python-dotenv
 
 
1
  openai>=0.27.0
2
+ python-dotenv
3
+ stability-sdk