File size: 3,171 Bytes
f274d93
 
 
 
 
 
 
 
 
 
 
b2ed8a8
f274d93
 
b2ed8a8
5b63bb8
f274d93
0f4ce60
 
e6c5ede
f274d93
 
 
 
 
 
 
 
e6c5ede
 
b7503f5
f274d93
 
e6c5ede
f274d93
e6c5ede
b2ed8a8
e6c5ede
f274d93
 
 
b2ed8a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f274d93
 
 
 
 
b2ed8a8
e6c5ede
f274d93
 
b2ed8a8
 
f274d93
b2ed8a8
f274d93
 
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
73
import gradio as gr
import numpy as np
import agent
import os

css_style = """
.gradio-container {
    font-family: "IBM Plex Mono";
}
"""

def agent_run(q, openai_api_key, mapi_api_key, serp_api_key):
    os.environ["OPENAI_API_KEY"]=openai_api_key
    os.environ["MAPI_API_KEY"]=mapi_api_key
    os.environ["SERPAPI_API_KEY"]=serp_api_key
    agent_chain = agent.Agent(openai_api_key, mapi_api_key)
    try: 
        out = agent_chain.run(q)
    except Exception as err:
        out = f"Something went wrong. Please try again.\nError: {err}"
    return out

with gr.Blocks(css=css_style) as demo:
    gr.Markdown(f'''
    # A LLM application developed during the LLM March *MADNESS* Hackathon
    - Developed by: Mayk Caldas ([@maykcaldas](https://github.com/maykcaldas)) and Sam Cox ([@SamCox822](https://github.com/SamCox822))

    ## What is this?
    - This is a demo of an app that can answer questions about material science using the [LangChain🦜️🔗](https://github.com/hwchase17/langchain/) and the [Materials Project API](https://materialsproject.org/).
    - Its behavior is based on Large Language Models (LLM), and it aims to be a tool to help scientists with quick predictions of numerous properties of materials.
    It is a work in progress, so please be patient with it. We are working on a systematic validation.


    ### Some keys are needed to use it:
    1. An openAI API key ( [Check it here](https://platform.openai.com/account/api-keys) )
    2. A Material Project's API key ( [Check it here](https://materialsproject.org/api#api-key) )
    3. A SERP API key ( [Check it here](https://serpapi.com/account-api) )
        - Only used if the chain runs a web search to answer the question.
    ''')
    with gr.Accordion("List of properties we developed tools for", open=False):
        gr.Markdown(f"""
        - Classification tasks: "Is the material AnByCz stable?"
            - Stable, 
            - Magnetic, 
            - Gap direct, and 
            - Metal.
        - Regression tasks: "What is the band gap of the material AnByCz?"
            - Band gap, 
            - Volume, 
            - Density, 
            - Atomic density, 
            - Formation energy per atom, 
            - Energy per atom, 
            - Electronic energy, 
            - Ionic energy, and 
            - Total energy.
        - Reaction procedure for synthesis proposal: "Give me a reaction procedure to synthesize the material AnByCz"(under development)
        """)
    openai_api_key = gr.Textbox(
        label="OpenAI API Key", placeholder="sk-...", type="password")
    mapi_api_key = gr.Textbox(
        label="Material Project API Key", placeholder="...", type="password")
    serp_api_key = gr.Textbox(
        label="Serp API Key", placeholder="...", type="password")
    with gr.Tab("MAPI Query"):
        text_input = gr.Textbox(label="", placeholder="Enter question here...")
        text_output = gr.Textbox(placeholder="Your answer will appear here...")
        text_button = gr.Button("Ask!")

    text_button.click(agent_run, inputs=[text_input, openai_api_key, mapi_api_key, serp_api_key], outputs=text_output)

demo.launch()