Spaces:
Paused
Paused
initial commit
Browse files- app.py +129 -0
- model.cbm +0 -0
- model_predvol.pkl +3 -0
- model_predwei.pkl +3 -0
- requirements.txt +6 -0
- web.py +176 -0
app.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import io
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from catboost import CatBoostRegressor
|
| 6 |
+
from web import HTMLCode, CSSCode, footCode
|
| 7 |
+
import numpy as np
|
| 8 |
+
import joblib
|
| 9 |
+
|
| 10 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2-1"
|
| 11 |
+
headers = {"Authorization": "Bearer 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"}
|
| 12 |
+
defaultprompt = "round table with blue color and smooth edges, places in the living room"
|
| 13 |
+
|
| 14 |
+
main_model = CatBoostRegressor()
|
| 15 |
+
main_model.load_model("model.cbm")
|
| 16 |
+
|
| 17 |
+
pred_vol = joblib.load('model_predvol.pkl')
|
| 18 |
+
pred_wei = joblib.load('model_predwei.pkl')
|
| 19 |
+
|
| 20 |
+
def query(payload):
|
| 21 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 22 |
+
return response.content
|
| 23 |
+
|
| 24 |
+
def stablefurniture(originalprompt, ftype, purpose, texture, length, width, height):
|
| 25 |
+
prompt = f"full {ftype} places in the living room {originalprompt} {texture} texture for {purpose}, having {int(length)} millimeter length, {int(width)} millimeter width, and {int(height)} millimeter height, hd quality, full furniture, hyperrealistic, highly detailed, sharp focus, cinematic lighting, for commercial website"
|
| 26 |
+
print(prompt)
|
| 27 |
+
image_bytes = query(
|
| 28 |
+
{
|
| 29 |
+
"inputs": prompt,
|
| 30 |
+
}
|
| 31 |
+
)
|
| 32 |
+
image = Image.open(io.BytesIO(image_bytes)).convert("RGBA")
|
| 33 |
+
# print(f"length: {length},width: {width},height: {height}")
|
| 34 |
+
vol_pred = pred_vol.predict([[length, width, height]])
|
| 35 |
+
wei_pred = pred_wei.predict([[length, width, height, vol_pred[0]]])
|
| 36 |
+
prediction = main_model.predict([length, width, height, vol_pred[0], wei_pred[0]])
|
| 37 |
+
rubles = "₽ " + str(np.round(prediction))
|
| 38 |
+
return image, rubles
|
| 39 |
+
|
| 40 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=CSSCode) as demo:
|
| 41 |
+
gr.HTML(HTMLCode)
|
| 42 |
+
with gr.Row():
|
| 43 |
+
with gr.Column(scale=1, min_width=600):
|
| 44 |
+
with gr.Row():
|
| 45 |
+
originalprompt = gr.Textbox(label="Prompt",default=defaultprompt)
|
| 46 |
+
with gr.Row():
|
| 47 |
+
ftype = gr.Dropdown(
|
| 48 |
+
[
|
| 49 |
+
"Table",
|
| 50 |
+
"Rack",
|
| 51 |
+
"Closet",
|
| 52 |
+
"Cabinet",
|
| 53 |
+
"Roll-out stand",
|
| 54 |
+
"Pedestal",
|
| 55 |
+
"Screen",
|
| 56 |
+
"Console",
|
| 57 |
+
"Reception Desk",
|
| 58 |
+
"Mezzanine",
|
| 59 |
+
"Penalty",
|
| 60 |
+
"Classical",
|
| 61 |
+
],
|
| 62 |
+
label="Type",
|
| 63 |
+
info="Which type of furniture are you looking for?",
|
| 64 |
+
)
|
| 65 |
+
purpose = gr.Dropdown(
|
| 66 |
+
[
|
| 67 |
+
"computer",
|
| 68 |
+
"for clothes",
|
| 69 |
+
"for documents",
|
| 70 |
+
"for negotiations",
|
| 71 |
+
"for office",
|
| 72 |
+
"for office equipment",
|
| 73 |
+
"for receptionists",
|
| 74 |
+
"for magazine",
|
| 75 |
+
"roll-out stand",
|
| 76 |
+
"writing",
|
| 77 |
+
],
|
| 78 |
+
label="Purpose",
|
| 79 |
+
info="How may your furnityre help you?",
|
| 80 |
+
)
|
| 81 |
+
texture = gr.Dropdown(
|
| 82 |
+
[
|
| 83 |
+
"Beech",
|
| 84 |
+
"Oak",
|
| 85 |
+
"Kraft white",
|
| 86 |
+
"Sonoma oak Light",
|
| 87 |
+
"Craft Golden",
|
| 88 |
+
"Wenge/Oak",
|
| 89 |
+
"Nut",
|
| 90 |
+
"Wine",
|
| 91 |
+
"Grey",
|
| 92 |
+
"Oak Cronberg",
|
| 93 |
+
"Cherry",
|
| 94 |
+
],
|
| 95 |
+
label="Texture",
|
| 96 |
+
info="How would you like it to be?",
|
| 97 |
+
)
|
| 98 |
+
with gr.Row():
|
| 99 |
+
length = gr.Number(label="Length")
|
| 100 |
+
width = gr.Number(label="Width")
|
| 101 |
+
height = gr.Number(label="Height")
|
| 102 |
+
btn = gr.Button("Dream")
|
| 103 |
+
prediction = gr.Textbox(label="Estimated Cost")
|
| 104 |
+
with gr.Column(scale=2, min_width=600):
|
| 105 |
+
furniture = gr.Image().style(height=580)
|
| 106 |
+
btn.click(
|
| 107 |
+
stablefurniture,
|
| 108 |
+
inputs=[originalprompt, ftype, texture, purpose, length, width, height],
|
| 109 |
+
outputs=[furniture, prediction],
|
| 110 |
+
)
|
| 111 |
+
with gr.Row():
|
| 112 |
+
gr.HTML(footCode)
|
| 113 |
+
|
| 114 |
+
demo.launch()
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
# gr.Interface(fn=stablefurniture, inputs=[
|
| 118 |
+
# gr.Textbox(),
|
| 119 |
+
# gr.Dropdown(
|
| 120 |
+
# ["Table","Rack","Closet","Cabinet","Roll-out stand","Pedestal","Screen","Console","Reception Desk","Mezzanine","Penalty","Classical"], label="Type", info="Which type of furniture are you looking for?"
|
| 121 |
+
# ),
|
| 122 |
+
# gr.Dropdown(
|
| 123 |
+
# ["computer","for clothes","for documents","for negotiations","for office","for office equipment","for receptionists","for magazine","roll-out stand","writing"], label="Purpose", info="Let us know why are you looking for this furniture.|"
|
| 124 |
+
# ),
|
| 125 |
+
# "number",
|
| 126 |
+
# "number",
|
| 127 |
+
# "number"],
|
| 128 |
+
# outputs=["image","number"],
|
| 129 |
+
# theme=gr.themes.Soft()).launch()
|
model.cbm
ADDED
|
Binary file (113 kB). View file
|
|
|
model_predvol.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c54b2c7b64a86c4a91ef4cba284c7813b1517a293713806c7345340b15cf91a0
|
| 3 |
+
size 644
|
model_predwei.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
HTMLCode = """
|
| 2 |
+
<head>
|
| 3 |
+
<link href="https://fonts.cdnfonts.com/css/vegapunk" rel="stylesheet">
|
| 4 |
+
<link href="https://fonts.cdnfonts.com/css/dustismo" rel="stylesheet">
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
</head>
|
| 8 |
+
<style>
|
| 9 |
+
@import url('https://fonts.cdnfonts.com/css/vegapunk');
|
| 10 |
+
@import url('https://fonts.cdnfonts.com/css/dustismo');
|
| 11 |
+
h1{
|
| 12 |
+
font-family:"Vegapunk", sans-serif;
|
| 13 |
+
}
|
| 14 |
+
p{
|
| 15 |
+
font-family: 'Dustismo', sans-serif;
|
| 16 |
+
|
| 17 |
+
}
|
| 18 |
+
</style>
|
| 19 |
+
<div style="text-align: center; margin: 0 auto;">
|
| 20 |
+
<div
|
| 21 |
+
style="
|
| 22 |
+
display: inline-flex;
|
| 23 |
+
align-items: center;
|
| 24 |
+
gap: 0.8rem;
|
| 25 |
+
font-size: 1.75rem;
|
| 26 |
+
"
|
| 27 |
+
>
|
| 28 |
+
<img src="https://seeklogo.com/images/U/ural-federal-university-logo-C368E954BC-seeklogo.com.png" style="height: 50px;" />
|
| 29 |
+
<h1 style="font-size: 50px; font-weight: 1200; margin-bottom: 7px;margin-top:5px;">
|
| 30 |
+
AlternoVation
|
| 31 |
+
</h1>
|
| 32 |
+
<img src="https://td-alterna.ru/design/alterna/images/logo_alt.svg" style="width: 50px; height: 50px; object-fit: cover; object-position: 0% 0" />
|
| 33 |
+
</div>
|
| 34 |
+
<p style="margin-bottom: 10px; font-size: 20px; line-height: 23px;">
|
| 35 |
+
"Take your office game up a notch - upgrade your workspace with ease & boost productivity on a budget!"
|
| 36 |
+
</p>
|
| 37 |
+
</div>
|
| 38 |
+
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
footCode = """
|
| 42 |
+
<p align="center">
|
| 43 |
+
<iframe title="Report Section" width="720" height="480"
|
| 44 |
+
src="https://app.powerbi.com/view?r=eyJrIjoiMTdjZWQ3ZmYtYzJkMy00YWM0LWFlODktNzkwOGU2NGU5ZDIyIiwidCI6ImYyM2M2Y2Y4LTVjY2MtNDhmMy04NzgzLWY3NWM3YzlkNjVkZiIsImMiOjl9"
|
| 45 |
+
frameborder="0"
|
| 46 |
+
align="center"
|
| 47 |
+
allowFullScreen="true">
|
| 48 |
+
</iframe>
|
| 49 |
+
</p>
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
CSSCode = """
|
| 53 |
+
.gradio-container {
|
| 54 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
| 55 |
+
}
|
| 56 |
+
.gr-button {
|
| 57 |
+
color: white;
|
| 58 |
+
border-color: black;
|
| 59 |
+
background: black;
|
| 60 |
+
}
|
| 61 |
+
input[type='range'] {
|
| 62 |
+
accent-color: black;
|
| 63 |
+
}
|
| 64 |
+
.dark input[type='range'] {
|
| 65 |
+
accent-color: #dfdfdf;
|
| 66 |
+
}
|
| 67 |
+
.container {
|
| 68 |
+
max-width: 730px;
|
| 69 |
+
margin: auto;
|
| 70 |
+
padding-top: 1.5rem;
|
| 71 |
+
}
|
| 72 |
+
#gallery {
|
| 73 |
+
min-height: 22rem;
|
| 74 |
+
margin-bottom: 15px;
|
| 75 |
+
margin-left: auto;
|
| 76 |
+
margin-right: auto;
|
| 77 |
+
border-bottom-right-radius: .5rem !important;
|
| 78 |
+
border-bottom-left-radius: .5rem !important;
|
| 79 |
+
}
|
| 80 |
+
#gallery>div>.h-full {
|
| 81 |
+
min-height: 20rem;
|
| 82 |
+
}
|
| 83 |
+
.details:hover {
|
| 84 |
+
text-decoration: underline;
|
| 85 |
+
}
|
| 86 |
+
.gr-button {
|
| 87 |
+
white-space: nowrap;
|
| 88 |
+
}
|
| 89 |
+
.gr-button:focus {
|
| 90 |
+
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
| 91 |
+
outline: none;
|
| 92 |
+
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
| 93 |
+
--tw-border-opacity: 1;
|
| 94 |
+
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
| 95 |
+
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
| 96 |
+
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
| 97 |
+
--tw-ring-opacity: .5;
|
| 98 |
+
}
|
| 99 |
+
#advanced-btn {
|
| 100 |
+
font-size: .7rem !important;
|
| 101 |
+
line-height: 19px;
|
| 102 |
+
margin-top: 12px;
|
| 103 |
+
margin-bottom: 12px;
|
| 104 |
+
padding: 2px 8px;
|
| 105 |
+
border-radius: 14px !important;
|
| 106 |
+
}
|
| 107 |
+
#advanced-options {
|
| 108 |
+
display: none;
|
| 109 |
+
margin-bottom: 20px;
|
| 110 |
+
}
|
| 111 |
+
.footer {
|
| 112 |
+
margin-bottom: 45px;
|
| 113 |
+
margin-top: 35px;
|
| 114 |
+
text-align: center;
|
| 115 |
+
border-bottom: 1px solid #e5e5e5;
|
| 116 |
+
}
|
| 117 |
+
.footer>p {
|
| 118 |
+
font-size: .8rem;
|
| 119 |
+
display: inline-block;
|
| 120 |
+
padding: 0 10px;
|
| 121 |
+
transform: translateY(10px);
|
| 122 |
+
background: white;
|
| 123 |
+
}
|
| 124 |
+
.dark .footer {
|
| 125 |
+
border-color: #303030;
|
| 126 |
+
}
|
| 127 |
+
.dark .footer>p {
|
| 128 |
+
background: #0b0f19;
|
| 129 |
+
}
|
| 130 |
+
.acknowledgments h4{
|
| 131 |
+
margin: 1.25em 0 .25em 0;
|
| 132 |
+
font-weight: bold;
|
| 133 |
+
font-size: 115%;
|
| 134 |
+
}
|
| 135 |
+
.animate-spin {
|
| 136 |
+
animation: spin 1s linear infinite;
|
| 137 |
+
}
|
| 138 |
+
@keyframes spin {
|
| 139 |
+
from {
|
| 140 |
+
transform: rotate(0deg);
|
| 141 |
+
}
|
| 142 |
+
to {
|
| 143 |
+
transform: rotate(360deg);
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
#share-btn-container {
|
| 147 |
+
display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
|
| 148 |
+
margin-top: 10px;
|
| 149 |
+
margin-left: auto;
|
| 150 |
+
}
|
| 151 |
+
#share-btn {
|
| 152 |
+
all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;right:0;
|
| 153 |
+
}
|
| 154 |
+
#share-btn * {
|
| 155 |
+
all: unset;
|
| 156 |
+
}
|
| 157 |
+
#share-btn-container div:nth-child(-n+2){
|
| 158 |
+
width: auto !important;
|
| 159 |
+
min-height: 0px !important;
|
| 160 |
+
}
|
| 161 |
+
#share-btn-container .wrap {
|
| 162 |
+
display: none !important;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
.gr-form{
|
| 166 |
+
flex: 1 1 50%; border-top-right-radius: 0; border-bottom-right-radius: 0;
|
| 167 |
+
}
|
| 168 |
+
#prompt-container{
|
| 169 |
+
gap: 0;
|
| 170 |
+
}
|
| 171 |
+
#prompt-text-input, #negative-prompt-text-input{padding: .45rem 0.625rem}
|
| 172 |
+
#component-16{border-top-width: 1px!important;margin-top: 1em}
|
| 173 |
+
.image_duplication{position: absolute; width: 100px; left: 50px}
|
| 174 |
+
|
| 175 |
+
footer {visibility: hidden}
|
| 176 |
+
"""
|