Usamadar707 commited on
Commit
80fa028
·
verified ·
1 Parent(s): 7a840b6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import gradio as gr
3
+ from PIL import Image
4
+ import io
5
+ import os
6
+
7
+ # API settings
8
+ API_URL = "https://api-inference.huggingface.co/models/e-n-v-y/envy-floorplans-xl-01"
9
+ headers = {"Authorization": f"Bearer {os.getenv('HF_API_KEY')}"}
10
+
11
+ def query(payload):
12
+ response = requests.post(API_URL, headers=headers, json=payload)
13
+ return response.content
14
+
15
+ def generate_room_plan(prompt):
16
+ image_bytes = query({"inputs": prompt})
17
+
18
+ # Convert the byte content to an image
19
+ image = Image.open(io.BytesIO(image_bytes))
20
+
21
+ return image
22
+
23
+ with gr.Blocks() as app:
24
+ gr.Markdown("# Room Plan Generator")
25
+
26
+ with gr.Row():
27
+ user_prompt = gr.Textbox(label="Enter your prompt for the room plan")
28
+
29
+ output = gr.Image(label="Generated Room Plan")
30
+
31
+ gr.Button("Generate Room Plan").click(
32
+ generate_room_plan,
33
+ inputs=[user_prompt],
34
+ outputs=output
35
+ )
36
+
37
+ app.launch()