Spaces:
Runtime error
Runtime error
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 | |
} |