File size: 2,885 Bytes
4e6a7cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94001b8
 
 
 
 
 
 
83a0c82
94001b8
 
 
 
 
 
 
4e6a7cd
 
94001b8
4e6a7cd
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
"""
Alloys inverse design
"""

import os
import csv
import gradio as gr
#from spaces_utils import authenticate


# Load tokens
WRITE_TOKEN = os.environ.get("WRITE_TOKEN") # read
READ_TOKEN = os.environ.get("READ_TOKEN") # read


# Logs repo path
dataset_url = "https://huggingface.co/datasets/sandl/upload_alloy_hardness"
dataset_path = "logs_alloy_hardness.csv"
  

def predict(x, request: gr.Request):
    """
    Use for debug
    """
    if request is not None:   # When building app first request is None
        message = f"{request.username}_{request.client.host}"
        write_logs(message, log_type="Prediction debug")
    return x


def authenticate_from_public(username, password):
    return authenticate(username, password, dataset_url, dataset_path)


def authenticate_debug(username, password):
    """
    Authentication function for debug
    """
    return username == password
    
css_styling = """#submit {background: #1eccd8} 
#submit:hover {background: #a2f1f6} 
.output-image, .input-image, .image-preview {height: 250px !important}
.output-plot {height: 250px !important}"""

light_theme_colors = gr.themes.Color(c50="#e4f3fa", # Dataframe background cell content - light mode only
                                c100="#e4f3fa", # Top corner of clear button in light mode + markdown text in dark mode
                                c200="#a1c6db", # Component borders
                                c300="#FFFFFF", # 
                                c400="#e4f3fa", # Footer text
                                c500="#0c1538", # Text of component headers in light mode only
                                c600="#a1c6db", # Top corner of button in dark mode
                                c700="#475383", # Button text in light mode + component borders in dark mode
                                c800="#0c1538", # Markdown text in light mode
                                c900="#a1c6db", # Background of dataframe - dark mode
                                c950="#0c1538") # Background in dark mode only
# secondary color used for highlight box content when typing in light mode, and download option in dark mode
# primary color used for login button in dark mode
osium_theme = gr.themes.Default(primary_hue="cyan", secondary_hue="cyan", neutral_hue=light_theme_colors)
page_title = "Alloys inverse design"
favicon_path = "osiumai_favicon.ico"
logo_path  = "osiumai_logo.jpg"
html = f"""<html> <link rel="icon" type="image/x-icon" href="file={favicon_path}">
<img src='file={logo_path}' alt='Osium AI logo' width='200' height='100'> </html>"""


with gr.Blocks(css=css_styling, theme=osium_theme, title=page_title) as demo_from_private:
    #gr.HTML(html)
    gr.Interface.load("spaces/sandl/private_inverse_design_alloy", api_key=READ_TOKEN, enable_queue=True)

if __name__ == "__main__":
    demo_from_private.launch(debug=True, enable_queue=True)