|
|
|
import gradio as gr |
|
import utilities as u |
|
import os |
|
import ctypes |
|
import store_helper as sh |
|
|
|
|
|
|
|
libc = ctypes.cdll.LoadLibrary("libc.so.6") |
|
M_MMAP_THRESHOLD = -3 |
|
|
|
|
|
libc.mallopt(M_MMAP_THRESHOLD, 2**20) |
|
|
|
|
|
base_dir = os.path.dirname(os.path.abspath(__file__)) |
|
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) |
|
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
|
store_description= gr.State() |
|
specialties_description = gr.State() |
|
|
|
def gen_store_desc(user_description): |
|
|
|
llm_output = sh.call_llm_and_cleanup(user_description) |
|
|
|
|
|
|
|
|
|
|
|
|
|
return [llm_output,llm_output] |
|
|
|
def gen_store_specialties(store_description): |
|
|
|
llm_output = sh.call_llm_and_cleanup(store_description, specialties=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
return [llm_output,llm_output] |
|
|
|
|
|
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) |
|
|
|
|