Spaces:
Runtime error
Runtime error
File size: 2,206 Bytes
172594a |
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 |
import os
import gradio as gr
from zipfile import ZipFile
from presets import *
def refresh_json_list(plain=False):
json_list = []
for root, dirs, files in os.walk("./index"):
for file in files:
if os.path.splitext(file)[1] == '.json':
json_list.append(os.path.splitext(file)[0])
if plain:
return json_list
return gr.Dropdown.update(choices=json_list)
def upload_file(file_obj):
files = []
with ZipFile(file_obj.name) as zfile:
for zinfo in zfile.infolist():
files.append(
{
"name": zinfo.filename,
}
)
return files
def reset_textbox():
return gr.update(value='')
def change_prompt_tmpl(tmpl_select):
new_tmpl = prompt_tmpl_dict[tmpl_select]
return gr.update(value=new_tmpl)
def parse_text(text):
lines = text.split("\n")
lines = [line for line in lines if line != ""]
count = 0
firstline = False
for i, line in enumerate(lines):
if "```" in line:
count += 1
items = line.split('`')
if count % 2 == 1:
lines[i] = f'<pre><code class="{items[-1]}">'
firstline = True
else:
lines[i] = f'</code></pre>'
else:
if i > 0:
if count % 2 == 1:
line = line.replace("&", "&")
line = line.replace("\"", "`\"`")
line = line.replace("\'", "`\'`")
line = line.replace("<", "<")
line = line.replace(">", ">")
line = line.replace(" ", " ")
line = line.replace("*", "*")
line = line.replace("_", "_")
line = line.replace("#", "#")
line = line.replace("-", "-")
line = line.replace(".", ".")
line = line.replace("!", "!")
line = line.replace("(", "(")
line = line.replace(")", ")")
lines[i] = "<br>"+line
text = "".join(lines)
return text
|