File size: 1,525 Bytes
5e79820
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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()