oleksandrburlakov commited on
Commit
67e7d91
·
1 Parent(s): f7dc109

Updated logic for generating image

Browse files
__pycache__/bot_actions.cpython-38.pyc DELETED
Binary file (1.6 kB)
 
bot_actions.py CHANGED
@@ -2,6 +2,7 @@ from openai import OpenAI
2
  import requests
3
  import time
4
  import os
 
5
 
6
  def save_record(arg_json):
7
  request_url = os.environ['facilityURL'] + "/facilities"
@@ -14,21 +15,27 @@ Write room-id in the center of room. Write room and floor size inside of room/fl
14
  Write floor description outside above the top border with margin 5px. Sizes must be proportional. Information should be based on next json: '''
15
 
16
  def generate_image(json_prompt):
17
- prompt = 'black and white building plan, 2d, top view:' + json_prompt
18
- openAIToken = os.environ['openAIToken']
19
- client = OpenAI(api_key=openAIToken)
20
- try:
21
- response = client.images.generate(
22
- n=1,
23
- prompt=prompt,
24
- model="dall-e-3",
25
- quality='hd',
26
- style='natural',
27
- )
28
- done_msg ="Done. Url:" + response.data[0].url
29
- return { "message": done_msg}
30
- except Exception as e:
31
- print(e)
 
 
 
 
 
 
32
 
33
 
34
  functions_dictionary = {
 
2
  import requests
3
  import time
4
  import os
5
+ import json
6
 
7
  def save_record(arg_json):
8
  request_url = os.environ['facilityURL'] + "/facilities"
 
15
  Write floor description outside above the top border with margin 5px. Sizes must be proportional. Information should be based on next json: '''
16
 
17
  def generate_image(json_prompt):
18
+ facility_information = json.loads(json_prompt)
19
+ if (len(facility_information["floors"]) > 0):
20
+ floor_information = facility_information["floors"][0]
21
+ prompt = 'black and white building plan, 2d, top view:' + json.dumps(floor_information)
22
+ openAIToken = os.environ['openAIToken']
23
+ client = OpenAI(api_key=openAIToken)
24
+ try:
25
+ response = client.images.generate(
26
+ n=1,
27
+ prompt=prompt,
28
+ model="dall-e-3",
29
+ quality='hd',
30
+ style='natural',
31
+ )
32
+ done_msg ="Done. Url:" + response.data[0].url
33
+ return { "message": done_msg}
34
+ except Exception as e:
35
+ print(e)
36
+ return { "message": "Error happened during execution"}
37
+ else:
38
+ return { "message": "Imposible to generate floor without floor information."}
39
 
40
 
41
  functions_dictionary = {