Spaces:
Runtime error
Runtime error
Commit
·
8dd971d
1
Parent(s):
3add56b
add streamlit app.py
Browse files- .gitattributes +0 -34
- .streamlit/config.toml +6 -0
- app.py +454 -0
.gitattributes
DELETED
|
@@ -1,34 +0,0 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.streamlit/config.toml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[theme]
|
| 2 |
+
base="light"
|
| 3 |
+
primaryColor="#246905"
|
| 4 |
+
[server]
|
| 5 |
+
enableXsrfProtection = false
|
| 6 |
+
enableWebsocketCompression = false
|
app.py
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
import numpy as np
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
import streamlit as st
|
| 7 |
+
from streamlit_ace import st_ace
|
| 8 |
+
from utils import *
|
| 9 |
+
from io import StringIO
|
| 10 |
+
import base64
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
import warnings
|
| 14 |
+
warnings.simplefilter("ignore", UserWarning)
|
| 15 |
+
|
| 16 |
+
API = 'http://4.193.50.237:5000/api'
|
| 17 |
+
|
| 18 |
+
@st.cache_data
|
| 19 |
+
def load_session():
|
| 20 |
+
return requests.Session()
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def translate_panel(seed, length):
|
| 24 |
+
with st.container():
|
| 25 |
+
st.header("Code Translation")
|
| 26 |
+
|
| 27 |
+
# Expand description panel
|
| 28 |
+
with st.expander('_:pencil: Quickly select demo example below_'):
|
| 29 |
+
option = st.selectbox(
|
| 30 |
+
'',
|
| 31 |
+
('Select Example', 'Example 1', 'Example 2', 'Example 3'),
|
| 32 |
+
key='trans'
|
| 33 |
+
)
|
| 34 |
+
example_code = ""
|
| 35 |
+
language = "python"
|
| 36 |
+
index=0
|
| 37 |
+
uploaded_file = st.file_uploader("or Upload your file: ", key='trans_file')
|
| 38 |
+
if uploaded_file:
|
| 39 |
+
# with open(uploaded_file, encoding='utf8') as f:
|
| 40 |
+
example_code = uploaded_file.read().decode()
|
| 41 |
+
|
| 42 |
+
if option == 'Example 1':
|
| 43 |
+
example_code = TRANS_EXAMPLE1
|
| 44 |
+
index=1
|
| 45 |
+
|
| 46 |
+
elif option == "Example 2":
|
| 47 |
+
example_code = TRANS_EXAMPLE2
|
| 48 |
+
language = "java"
|
| 49 |
+
index=0
|
| 50 |
+
|
| 51 |
+
elif option == "Example 3":
|
| 52 |
+
example_code = TRANS_EXAMPLE3
|
| 53 |
+
language = "java"
|
| 54 |
+
index=0
|
| 55 |
+
|
| 56 |
+
if example_code == '':
|
| 57 |
+
content = st_ace('', placeholder="Input your code in HERE", language='python', auto_update=True, key="<trans-code>")
|
| 58 |
+
else:
|
| 59 |
+
content = st_ace(example_code, placeholder="Input your code in HERE", language=language, auto_update=True)
|
| 60 |
+
|
| 61 |
+
target_lgs = st.selectbox(
|
| 62 |
+
'*Select your target translate languages:*',
|
| 63 |
+
('Python', 'Java'),
|
| 64 |
+
index=index
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
if st.button("**:repeat: Translate Code**"):
|
| 68 |
+
with st.spinner('Translating...'):
|
| 69 |
+
source_lgs = detect_lang(API, content)
|
| 70 |
+
|
| 71 |
+
if target_lgs == source_lgs:
|
| 72 |
+
st.warning('Selected language can not be equal to source language', icon="⚠️")
|
| 73 |
+
trans_code = content
|
| 74 |
+
else:
|
| 75 |
+
trans_code = request_api(
|
| 76 |
+
url=API,
|
| 77 |
+
data={
|
| 78 |
+
'input': content,
|
| 79 |
+
'task': 'translate',
|
| 80 |
+
'source_lgs': source_lgs,
|
| 81 |
+
'target_lgs': target_lgs,
|
| 82 |
+
'seed': seed,
|
| 83 |
+
'length': length
|
| 84 |
+
},
|
| 85 |
+
)
|
| 86 |
+
trans_code = json.loads(trans_code.text)
|
| 87 |
+
trans_code = trans_code['output']
|
| 88 |
+
|
| 89 |
+
st.write("Translated Code")
|
| 90 |
+
st.code(trans_code, language=target_lgs.lower())
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def complete_panel(seed, length):
|
| 94 |
+
with st.container():
|
| 95 |
+
st.header("Code Completion")
|
| 96 |
+
|
| 97 |
+
# Expand description panel
|
| 98 |
+
with st.expander('_:pencil: Quickly select demo example below_'):
|
| 99 |
+
option = st.selectbox(
|
| 100 |
+
'',
|
| 101 |
+
('Select Example', 'Example 1', 'Example 2', 'Example 3'),
|
| 102 |
+
key='complete'
|
| 103 |
+
)
|
| 104 |
+
example_code = ""
|
| 105 |
+
|
| 106 |
+
if option == 'Example 1':
|
| 107 |
+
example_code = COM_EXAMPLE1
|
| 108 |
+
|
| 109 |
+
if option == "Example 2":
|
| 110 |
+
example_code = COM_EXAMPLE2
|
| 111 |
+
|
| 112 |
+
if option == "Example 3":
|
| 113 |
+
example_code = COM_EXAMPLE3
|
| 114 |
+
|
| 115 |
+
if example_code == '':
|
| 116 |
+
content = st_ace('', placeholder="Input your code in HERE", language='python', auto_update=True, key="<complete-code>")
|
| 117 |
+
else:
|
| 118 |
+
content = st_ace(example_code, placeholder="Input your code in HERE", language='python', auto_update=True)
|
| 119 |
+
|
| 120 |
+
if st.button("**:writing_hand: Complete Code**"):
|
| 121 |
+
with st.spinner('Completing ...'):
|
| 122 |
+
source_lgs = detect_lang(API, content)
|
| 123 |
+
trans_code = request_api(
|
| 124 |
+
url=API,
|
| 125 |
+
data={
|
| 126 |
+
'input': content,
|
| 127 |
+
'task': 'completion',
|
| 128 |
+
'source_lgs': source_lgs,
|
| 129 |
+
'target_lgs': None,
|
| 130 |
+
'seed': seed,
|
| 131 |
+
'length': length
|
| 132 |
+
},
|
| 133 |
+
)
|
| 134 |
+
trans_code = json.loads(trans_code.text)
|
| 135 |
+
|
| 136 |
+
st.write("Completed Code")
|
| 137 |
+
code = str(content).strip() + trans_code['output']
|
| 138 |
+
st.code(code, language=source_lgs.lower())
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def repair_panel(seed, length):
|
| 142 |
+
with st.container():
|
| 143 |
+
st.header("Code Repair")
|
| 144 |
+
|
| 145 |
+
# Expand description panel
|
| 146 |
+
with st.expander('_:pencil: Quickly select demo example below_'):
|
| 147 |
+
option = st.selectbox(
|
| 148 |
+
'',
|
| 149 |
+
('Select Example', 'Example 1', 'Example 2', 'Example 3'),
|
| 150 |
+
key='<example-repair>'
|
| 151 |
+
)
|
| 152 |
+
example_code = ""
|
| 153 |
+
|
| 154 |
+
if option == 'Example 1':
|
| 155 |
+
example_code = RE_EXAMPLE1
|
| 156 |
+
|
| 157 |
+
if option == "Example 2":
|
| 158 |
+
example_code = RE_EXAMPLE2
|
| 159 |
+
|
| 160 |
+
if option == "Example 3":
|
| 161 |
+
example_code = RE_EXAMPLE3
|
| 162 |
+
|
| 163 |
+
if example_code == '':
|
| 164 |
+
content = st_ace('', placeholder="Input your code in HERE", language='python', auto_update=True, key="<repair-code>")
|
| 165 |
+
else:
|
| 166 |
+
content = st_ace(example_code, placeholder="Input your code in HERE", language='python', auto_update=True)
|
| 167 |
+
|
| 168 |
+
if st.button("**:hammer_and_wrench: Repair Code**"):
|
| 169 |
+
with st.spinner('Repairing . . .'):
|
| 170 |
+
source_lgs = detect_lang(API, content)
|
| 171 |
+
trans_code = request_api(
|
| 172 |
+
url=API,
|
| 173 |
+
data={
|
| 174 |
+
'input': content,
|
| 175 |
+
'task': 'code_repair',
|
| 176 |
+
'source_lgs': source_lgs,
|
| 177 |
+
'target_lgs': None,
|
| 178 |
+
'seed': seed,
|
| 179 |
+
'length': length
|
| 180 |
+
},
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
trans_code = json.loads(trans_code.text)
|
| 184 |
+
|
| 185 |
+
st.write("Repaired Code")
|
| 186 |
+
code = trans_code['output']
|
| 187 |
+
st.code(code, language=source_lgs.lower())
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def codegen_panel(seed, length):
|
| 191 |
+
with st.container():
|
| 192 |
+
st.header("Code Generation")
|
| 193 |
+
|
| 194 |
+
# Expand description panel
|
| 195 |
+
with st.expander('_:pencil: Quickly select demo example below_'):
|
| 196 |
+
option = st.selectbox(
|
| 197 |
+
'',
|
| 198 |
+
('Select Example', 'Example 1', 'Example 2', 'Example 3'),
|
| 199 |
+
key='<example-code-gen>'
|
| 200 |
+
)
|
| 201 |
+
example_code = ""
|
| 202 |
+
uploaded_file = st.file_uploader("or Upload your file: ", key='gen_file')
|
| 203 |
+
if uploaded_file:
|
| 204 |
+
example_code = uploaded_file.read().decode()
|
| 205 |
+
|
| 206 |
+
if option == 'Example 1':
|
| 207 |
+
example_code = CGEN_EXAMPLE1
|
| 208 |
+
|
| 209 |
+
if option == "Example 2":
|
| 210 |
+
example_code = CGEN_EXAMPLE2
|
| 211 |
+
|
| 212 |
+
if option == "Example 3":
|
| 213 |
+
example_code = CGEN_EXAMPLE3
|
| 214 |
+
|
| 215 |
+
if example_code == '':
|
| 216 |
+
content = st_ace('', placeholder="Input your code in HERE", auto_update=True, key="<gen-code-code>")
|
| 217 |
+
else:
|
| 218 |
+
content = st_ace(example_code, placeholder="Input your code in HERE", auto_update=True)
|
| 219 |
+
|
| 220 |
+
target_lgs = st.selectbox(
|
| 221 |
+
'*Select your target translate languages:*',
|
| 222 |
+
('Python', 'Java'),
|
| 223 |
+
index=0,
|
| 224 |
+
key="gen_select"
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
+
if st.button("**:hammer: Generate Code**"):
|
| 228 |
+
with st.spinner('Generating . . .'):
|
| 229 |
+
trans_code = request_api(
|
| 230 |
+
url=API,
|
| 231 |
+
data={
|
| 232 |
+
'input': content,
|
| 233 |
+
'task': 'text2code',
|
| 234 |
+
'source_lgs': target_lgs.lower(),
|
| 235 |
+
'target_lgs': None,
|
| 236 |
+
'seed': seed,
|
| 237 |
+
'length': length
|
| 238 |
+
},
|
| 239 |
+
)
|
| 240 |
+
|
| 241 |
+
trans_code = json.loads(trans_code.text)
|
| 242 |
+
|
| 243 |
+
st.write("Generated Code")
|
| 244 |
+
code = trans_code['output']
|
| 245 |
+
st.code(code, language=target_lgs.lower())
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def codesum_panel(seed, length):
|
| 249 |
+
with st.container():
|
| 250 |
+
st.header("Code Summarization")
|
| 251 |
+
|
| 252 |
+
# Expand description panel
|
| 253 |
+
with st.expander('_:pencil: Quickly select demo example below_'):
|
| 254 |
+
option = st.selectbox(
|
| 255 |
+
'',
|
| 256 |
+
('Select Example', 'Example 1', 'Example 2', 'Example 3'),
|
| 257 |
+
key='<example-sum>'
|
| 258 |
+
)
|
| 259 |
+
example_code = ""
|
| 260 |
+
uploaded_file = st.file_uploader("or Upload your file: ", key='sum_file')
|
| 261 |
+
if uploaded_file:
|
| 262 |
+
# with open(uploaded_file, encoding='utf8') as f:
|
| 263 |
+
example_code = uploaded_file.read().decode()
|
| 264 |
+
|
| 265 |
+
if option == 'Example 1':
|
| 266 |
+
example_code = SUM_EXAMPLE1
|
| 267 |
+
|
| 268 |
+
if option == "Example 2":
|
| 269 |
+
example_code = SUM_EXAMPLE2
|
| 270 |
+
|
| 271 |
+
if option == "Example 3":
|
| 272 |
+
example_code = SUM_EXAMPLE3
|
| 273 |
+
|
| 274 |
+
if example_code == '':
|
| 275 |
+
content = st_ace('', placeholder="Input your code in HERE", language='python', auto_update=True, key="<sum-code>")
|
| 276 |
+
else:
|
| 277 |
+
content = st_ace(example_code, placeholder="Input your code in HERE", language='python', auto_update=True)
|
| 278 |
+
|
| 279 |
+
task = 'code2text'
|
| 280 |
+
with st.expander('Advanced Option'):
|
| 281 |
+
param = st.checkbox('Summarize with param')
|
| 282 |
+
if param:
|
| 283 |
+
task += '_param'
|
| 284 |
+
if st.button("**:hammer_and_wrench: Summarize Code**"):
|
| 285 |
+
|
| 286 |
+
with st.spinner('Summarizing . . .'):
|
| 287 |
+
source_lgs = detect_lang(API, content)
|
| 288 |
+
trans_code = request_api(
|
| 289 |
+
url=API,
|
| 290 |
+
data={
|
| 291 |
+
'input': content,
|
| 292 |
+
'task': task,
|
| 293 |
+
'source_lgs': source_lgs,
|
| 294 |
+
'target_lgs': None,
|
| 295 |
+
'seed': seed,
|
| 296 |
+
'length': length
|
| 297 |
+
},
|
| 298 |
+
)
|
| 299 |
+
trans_code = json.loads(trans_code.text)
|
| 300 |
+
|
| 301 |
+
st.write("Summarized Code")
|
| 302 |
+
code = trans_code['output']
|
| 303 |
+
st.code(code, language=source_lgs.lower())
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
def testgen_panel(seed, length):
|
| 307 |
+
with st.container():
|
| 308 |
+
st.header("Test Generation")
|
| 309 |
+
|
| 310 |
+
# Expand description panel
|
| 311 |
+
with st.expander('_:pencil: Quickly select demo example below_'):
|
| 312 |
+
option = st.selectbox(
|
| 313 |
+
'',
|
| 314 |
+
('Select Example', 'Example 1', 'Example 2', 'Example 3'),
|
| 315 |
+
key='<example-test>'
|
| 316 |
+
)
|
| 317 |
+
example_code = ""
|
| 318 |
+
|
| 319 |
+
if option == 'Example 1':
|
| 320 |
+
example_code = TEST_EXAMPLE1
|
| 321 |
+
|
| 322 |
+
if option == "Example 2":
|
| 323 |
+
example_code = TEST_EXAMPLE2
|
| 324 |
+
|
| 325 |
+
if option == "Example 3":
|
| 326 |
+
example_code = TEST_EXAMPLE3
|
| 327 |
+
|
| 328 |
+
st.warning('Feature only support Java', icon="⚠️")
|
| 329 |
+
|
| 330 |
+
if example_code == '':
|
| 331 |
+
content = st_ace('', placeholder="Input your code in HERE", language='python', auto_update=True, key="<test-code>")
|
| 332 |
+
else:
|
| 333 |
+
content = st_ace(example_code, placeholder="Input your code in HERE", language='python', auto_update=True)
|
| 334 |
+
|
| 335 |
+
if st.button("**:hammer_and_wrench: Generate Test**"):
|
| 336 |
+
with st.spinner('Generating . . .'):
|
| 337 |
+
source_lgs = detect_lang(API, content)
|
| 338 |
+
trans_code = request_api(
|
| 339 |
+
url=API,
|
| 340 |
+
data={
|
| 341 |
+
'input': content,
|
| 342 |
+
'task': 'testgen',
|
| 343 |
+
'source_lgs': source_lgs,
|
| 344 |
+
'target_lgs': None,
|
| 345 |
+
'seed': seed,
|
| 346 |
+
'length': length
|
| 347 |
+
},
|
| 348 |
+
)
|
| 349 |
+
print(trans_code.text)
|
| 350 |
+
trans_code = json.loads(trans_code.text)
|
| 351 |
+
|
| 352 |
+
st.write("Generated Test")
|
| 353 |
+
code = trans_code['output']
|
| 354 |
+
st.code(code, language=source_lgs.lower())
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
def member_infor(image_path, INFOR):
|
| 358 |
+
col_1, col_2, col_3, col_4 = st.columns([1,1,2,6])
|
| 359 |
+
avatar_image = Image.open(image_path)
|
| 360 |
+
with col_2:
|
| 361 |
+
st.image(avatar_image, width=100)
|
| 362 |
+
with col_4:
|
| 363 |
+
st.markdown(INFOR, unsafe_allow_html=True)
|
| 364 |
+
|
| 365 |
+
def logo(image_path):
|
| 366 |
+
logo = load_image_from_local(image_path)
|
| 367 |
+
st.image(logo, width=100)
|
| 368 |
+
|
| 369 |
+
def main_app():
|
| 370 |
+
st.set_page_config(
|
| 371 |
+
page_title="Docify-Lab",
|
| 372 |
+
page_icon="🧊",
|
| 373 |
+
layout="wide",
|
| 374 |
+
# initial_sidebar_state="expanded"
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
col_title1, col_title2 = st.columns([1.5, 20])
|
| 378 |
+
avatar_image = Image.open('./assets/ava_app.png')
|
| 379 |
+
# st.markdown("<p style='text-align: center; color: grey;'>"+img_to_html('./assets/ava_app.png')+"</p>", unsafe_allow_html=True)
|
| 380 |
+
|
| 381 |
+
with col_title1:
|
| 382 |
+
st.image(avatar_image, width=70)
|
| 383 |
+
# st.markdown("<p style='text-align: center; color: grey; width: 64px;'>"+img_to_html('./assets/ava_app.png')+"</p>", unsafe_allow_html=True)
|
| 384 |
+
|
| 385 |
+
with col_title2:
|
| 386 |
+
st.title(" Welcome to Docify-Lab")
|
| 387 |
+
|
| 388 |
+
# layout
|
| 389 |
+
col1, col2 = st.columns([6, 4])
|
| 390 |
+
# sess = load_session()
|
| 391 |
+
|
| 392 |
+
# Advanced option
|
| 393 |
+
st.sidebar.write("Advanced Custom")
|
| 394 |
+
length = st.sidebar.slider('Generate length', 16, 1024, 512, 32)
|
| 395 |
+
seed = st.sidebar.number_input('Model seed:', value=42, min_value=1, step=1)
|
| 396 |
+
|
| 397 |
+
with col1:
|
| 398 |
+
|
| 399 |
+
tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(
|
| 400 |
+
["Code Translation", "Test Generation", "Code Repair",
|
| 401 |
+
"Code Summarization", "Code Generation", "Code Completion"]
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
with tab1:
|
| 405 |
+
translate_panel(seed, length)
|
| 406 |
+
with tab2:
|
| 407 |
+
testgen_panel(seed, length)
|
| 408 |
+
with tab3:
|
| 409 |
+
repair_panel(seed, length)
|
| 410 |
+
with tab4:
|
| 411 |
+
codesum_panel(seed, length)
|
| 412 |
+
with tab5:
|
| 413 |
+
codegen_panel(seed, length)
|
| 414 |
+
with tab6:
|
| 415 |
+
complete_panel(seed, length)
|
| 416 |
+
|
| 417 |
+
with col2:
|
| 418 |
+
c1, c2, c3, c4, c5, c6, c7 = st.columns([1,1,1,1,1,1,1])
|
| 419 |
+
|
| 420 |
+
with c2:
|
| 421 |
+
logo("./assets/fpt_logo.png")
|
| 422 |
+
with c4:
|
| 423 |
+
logo("./assets/AI_center_logo.png")
|
| 424 |
+
with c6:
|
| 425 |
+
logo("./assets/Docify-Logo.png")
|
| 426 |
+
# st.markdown(SIDEBAR_INFO, unsafe_allow_html=True)
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
with st.expander("What is Docify-Lab?", expanded=True):
|
| 430 |
+
st.markdown(STORY, unsafe_allow_html=True)
|
| 431 |
+
|
| 432 |
+
with st.expander("Docify Lab - FPT Software AI Center", expanded=True):
|
| 433 |
+
tab_t1, tab_1, tab_t2, tab_t3, tab_t4, tab_t5, tab_t6 = st.tabs(
|
| 434 |
+
["About Us", "Leader","Member 1", "Member 2",
|
| 435 |
+
"Member 3", "Member 4", "Member 5"],
|
| 436 |
+
)
|
| 437 |
+
|
| 438 |
+
with tab_t1:
|
| 439 |
+
st.markdown(GROUP_INFO, unsafe_allow_html=True)
|
| 440 |
+
with tab_1:
|
| 441 |
+
member_infor('./assets/Anh_Nghi_ava.png', LEADER_INFOR)
|
| 442 |
+
with tab_t2:
|
| 443 |
+
member_infor('./assets/Nam_ava.png', NAM_INFOR)
|
| 444 |
+
with tab_t3:
|
| 445 |
+
member_infor('./assets/Dung_ava.jpg', DUNG_INFOR)
|
| 446 |
+
with tab_t4:
|
| 447 |
+
member_infor('./assets/Minh_ava.JPG', MINH_INFOR)
|
| 448 |
+
with tab_t5:
|
| 449 |
+
member_infor('./assets/VA_ava.jpg', VA_INFOR)
|
| 450 |
+
with tab_t6:
|
| 451 |
+
member_infor('./assets/KA_ava.jpg', KA_INFOR)
|
| 452 |
+
|
| 453 |
+
if __name__ == '__main__':
|
| 454 |
+
main_app()
|