File size: 1,042 Bytes
e16bfc3
 
6c339ed
 
e16bfc3
 
 
 
 
 
 
 
 
 
 
 
 
9a59f65
e16bfc3
6c339ed
e16bfc3
 
 
 
 
 
 
 
cc8d662
 
 
 
 
 
e16bfc3
 
 
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
import gradio as gr
import os
from dotenv import load_dotenv
load_dotenv()

def get_markdown(registry):
    with open(registry,"r") as f:
        return f.read()

def get_interface(md):
    code = "import" + md.split("import")[2].split(".launch")[0]
    return code

    


# need to match the filenames in the regesteries folder
possible_registries = ["gemini-gradio","openai-gradio"]

with gr.Blocks(fill_height=False, fill_width=False) as demo : 
    gr.Markdown("<h1 style='text-align: center;'>Gradio registry</h1>")
    dropdown = gr.Dropdown(possible_registries,value=possible_registries[0],interactive=True)
    
    @gr.render(inputs=dropdown)
    def create_interface(registry):
        filepath = f"registries/{registry}.md"
        md = get_markdown(filepath)
        gr.Markdown(md)
        try : 
            code = get_interface(md)
            exec(code)
        except Exception as e : 
            message = f"could not render the interface because of the following error : {e} "
            gr.Info(message)


demo.launch()