File size: 1,581 Bytes
f7dc109
56506e9
 
ece0caf
67e7d91
56506e9
 
ece0caf
 
56506e9
ca36ef4
 
 
 
 
 
 
67e7d91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ca36ef4
56506e9
 
ca36ef4
 
56506e9
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from openai import OpenAI
import requests
import time
import os
import json

def save_record(arg_json):
  request_url = os.environ['facilityURL'] + "/facilities"
  r = requests.post(request_url, json={'pk': round(time.time()), 'json': arg_json})
  print(r.status_code, r.reason)
  return { "message": "Done" }

instruction = '''black-and-white building plan, 2d, flat, house-building plan, top view. Rooms according to locations. 
Write room-id in the center of room. Write room and floor size inside of room/floor at the top. 
Write floor description outside above the top border with margin 5px. Sizes must be proportional. Information should be based on next json: '''

def generate_image(json_prompt):
  facility_information = json.loads(json_prompt)
  if (len(facility_information["floors"]) > 0):
    floor_information = facility_information["floors"][0]
    prompt = 'black and white building plan, 2d, top view:' +  json.dumps(floor_information)
    openAIToken = os.environ['openAIToken']
    client = OpenAI(api_key=openAIToken)
    try:
      response = client.images.generate(
        n=1,
        prompt=prompt,
        model="dall-e-3",
        quality='hd',
        style='natural',
      )
      done_msg ="Done. Url:" + response.data[0].url 
      return { "message": done_msg}
    except Exception as e:
      print(e)
      return { "message": "Error happened during execution"}
  else:
    return { "message": "Imposible to generate floor without floor information."}


functions_dictionary = {
  "save_record": save_record,
  "generate_image": generate_image
}