File size: 4,414 Bytes
27c79bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# this imports the code from files and modules
import gradio as gr
import utilities as u
import os
import ctypes
import store_helper as sh


# This is a fix for the way that python doesn't release system memory back to the OS and it was leading to locking up the system
libc = ctypes.cdll.LoadLibrary("libc.so.6")
M_MMAP_THRESHOLD = -3

# Set malloc mmap threshold.
libc.mallopt(M_MMAP_THRESHOLD, 2**20)

# Declare accessible directories
base_dir = os.path.dirname(os.path.abspath(__file__))  # Gets the directory where the script is located
print(f"Base Directory :",base_dir)
list_of_static_dir = [os.path.join(base_dir, "output"), 
                    os.path.join(base_dir, "dependencies"),
                    os.path.join(base_dir, "galleries")] 
gr.set_static_paths(paths=list_of_static_dir)

# Build gradio app
# Storing everything inside the Blocks to be accessible to the app

with gr.Blocks() as demo:
    # Functions and State Variables
    store_description= gr.State()
    specialties_description = gr.State()

    def gen_store_desc(user_description): 
        
        llm_output = sh.call_llm_and_cleanup(user_description)
        #user_monster = sh.convert_to_dict(llm_output)
        #user_monster = llm_output
        #keys_list = list(user_monster)
            
        
        #Return each State variable twice, once to the variable and once to the textbox
        return [llm_output,llm_output]
    
    def gen_store_specialties(store_description): 
        
        llm_output = sh.call_llm_and_cleanup(store_description, specialties=True)
        #user_monster = sh.convert_to_dict(llm_output)
        #user_monster = llm_output
        #keys_list = list(user_monster)
            
        
        #Return each State variable twice, once to the variable and once to the textbox
        return [llm_output,llm_output]

    #Function to dynamically render textbox if it has text.                
    def update_visibility(textbox):        
        if not textbox:
            return gr.update(visible=False)
        return gr.update(visible=True)
    with gr.Tab("Store"):
        user_store_description = gr.Textbox(label = "Step 1 : What are the core qualities of the store?",
                                                lines = 1, placeholder=f"Ex : A trade shop with a female ogre merchant, basic trade goods and travel supplies, has a secret basement for smuggling.",
                                                elem_id= "custom-textbox")
        desc_gen = gr.Button(value = "Click to Generate Description")
        store_description_output = gr.Textbox(label = 'Description', lines = 2, interactive=True, visible=True)
        store_description_output.change(fn=update_visibility,
                                                    inputs=[store_description_output],
                                                    outputs=[store_description_output])
        desc_gen.click(fn = gen_store_desc, inputs = [user_store_description],
                        outputs= [store_description, store_description_output                                    
                                    ])

        image_path_list= u.absolute_path("./folder_with_images")
    
    with gr.Tab("Inventory"):
        user_store_description = gr.Textbox(label = "Step 1 : What are the core qualities of the store?",
                                                lines = 1, placeholder=f"Ex : A trade shop with a female ogre merchant, basic trade goods and travel supplies, has a secret basement for smuggling.",
                                                elem_id= "custom-textbox")
        desc_gen = gr.Button(value = "Click to Generate Description")
        store_description_output = gr.Textbox(label = 'Description', lines = 2, interactive=True, visible=True)
        store_description_output.change(fn=update_visibility,
                                                    inputs=[store_description_output],
                                                    outputs=[store_description_output])
        desc_gen.click(fn = gen_store_desc, inputs = [user_store_description],
                        outputs= [store_description, store_description_output                                    
                                    ])

        image_path_list= u.absolute_path("./folder_with_images")
    if __name__ == "__main__":
        demo.launch(allowed_paths=list_of_static_dir)