maulana-m commited on
Commit
613eacb
1 Parent(s): c57444b

initial commit

Browse files
Files changed (2) hide show
  1. app.py +73 -0
  2. config.py +9 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import requests
4
+ import config as cfg
5
+
6
+
7
+ DEFAULT_SKILL = ["A", "B"]
8
+ ENVS = ["canary", "production"]
9
+
10
+
11
+ MARKDOWN = """## Skill Repository
12
+ How to Use:
13
+ 1. Click 'Get All skills' to get list of skill.
14
+ 2. Choose specific skill that need to be updated
15
+ 3. Click Get Skill Data to get skill information related prompt and config
16
+ 4. Edit prompt and config, then click update skill to save and update the skill
17
+ """
18
+
19
+
20
+ def edit_persona(skill_name, config_json, skprompt):
21
+ # todo update using API
22
+ return "Success"
23
+
24
+
25
+ def get_all_skills():
26
+ response = requests.get(cfg.URL_SKILLS)
27
+ if response.status_code == 200:
28
+ result = response.json()["data"]["skills"]
29
+ else:
30
+ result = []
31
+ return gr.Dropdown(choices=result)
32
+
33
+
34
+ def get_skill_data(skill_name, env):
35
+ URL = cfg.URL_SKILL + "/{}?env={}".format(skill_name, env)
36
+ prompt, config_json = "", ""
37
+ response = requests.get(URL)
38
+ if response.status_code == 200:
39
+ data = response.json()["data"]
40
+ prompt = data["prompt"]
41
+ config_json = json.dumps(data["config"], indent=4)
42
+
43
+ return prompt, config_json
44
+
45
+
46
+ with gr.Blocks() as demo:
47
+ gr.Markdown(MARKDOWN)
48
+ skills = gr.Button("1. Get All skills")
49
+ with gr.Row():
50
+ with gr.Column(scale=5):
51
+ env = gr.Dropdown(ENVS, label="Environment")
52
+ with gr.Column(scale=5):
53
+ skill_name = gr.Dropdown(DEFAULT_SKILL, label="Skill")
54
+
55
+ skill_data = gr.Button("2. Get Skill Data")
56
+ prompt = gr.Textbox(placeholder="You are helpful assistence", lines=10, label="skprompt")
57
+ config_json = gr.Textbox(placeholder="Config Json", lines=5, label="config json")
58
+
59
+ with gr.Row():
60
+ with gr.Column(scale=5):
61
+ update_skill = gr.Button("3. Save and Update Skill")
62
+ with gr.Column(scale=5):
63
+ status_box = gr.Textbox(label="Status code from server", )
64
+
65
+ skills.click(get_all_skills, [], [skill_name], concurrency_limit=cfg.QUEUE_CONCURENCY_COUNT)
66
+ skill_data.click(get_skill_data, [skill_name, env], [prompt, config_json], concurrency_limit=cfg.QUEUE_CONCURENCY_COUNT)
67
+ update_skill.click(edit_persona, [skill_name, prompt, config_json], [status_box], concurrency_limit=cfg.QUEUE_CONCURENCY_COUNT)
68
+
69
+ (
70
+ demo
71
+ .queue(max_size=cfg.QUEUE_MAX_SIZE)
72
+ .launch(auth=(cfg.USERNAME, cfg.PASSWORD), debug=True)
73
+ )
config.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+
4
+ USERNAME = os.getenv("USERNAME")
5
+ PASSWORD = os.getenv("PASSWORD")
6
+ URL_SKILLS = os.getenv("URL_ALL_SKILLS")
7
+ URL_SKILL = os.getenv("URL_SKILL")
8
+ QUEUE_MAX_SIZE = int(os.getenv("QUEUE_MAX_SIZE", 20))
9
+ QUEUE_CONCURENCY_COUNT = int(os.getenv("QUEUE_CONCURENCY_COUNT", 10))