File size: 1,215 Bytes
f7dc109
56506e9
 
ece0caf
56506e9
 
ece0caf
 
56506e9
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
from openai import OpenAI
import requests
import time
import os

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):
  prompt = 'black and white building plan, 2d, top view:' +  json_prompt
  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)


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