Spaces:
Sleeping
Sleeping
# app.py | |
import gradio as gr | |
from sustanability_scorer import ( | |
sustainability_scorer, | |
openai_completion, | |
HouseFeature, | |
encode_image, | |
) | |
import json | |
def combined_function(image): | |
base64_image = encode_image(image, output_format="PNG") | |
resp = openai_completion(base64_image) # response in string | |
# Convert the response to a dictionary | |
house_features = json.loads(resp) | |
score = sustainability_scorer(HouseFeature(**house_features)) | |
return score | |
with gr.Blocks() as app: | |
gr.Markdown("## Sustainability Scorer") | |
with gr.Row(): | |
with gr.Column(): | |
image_input = gr.Image( | |
type="pil", | |
label="Upload Image", | |
) | |
submit_button = gr.Button("Submit") | |
with gr.Column(): | |
score_output = gr.HTML() | |
submit_button.click(combined_function, inputs=image_input, outputs=score_output) | |
# Add CSS styles | |
gr.HTML( | |
""" | |
<style> | |
.score_output { | |
font-size: 58px; | |
font-weight: bold; | |
padding: 10px; | |
border-radius: 5px; | |
background-color: #f4f4f9; | |
text-align: center; | |
transition: all 0.3s ease; | |
margin-top: 20px; | |
} | |
</style> | |
""" | |
) | |
examples = gr.Examples( | |
examples=[ | |
["example1.png"], | |
["example2.png"], | |
["example3.png"], | |
], | |
inputs=image_input, | |
) | |
# interface.launch() | |
app.launch() | |