Spaces:
Build error
Build error
embed js and css in to chatbot.html
Browse files- app/app.py +13 -16
- app/chatbot.html +2 -2
app/app.py
CHANGED
@@ -8,7 +8,6 @@ from transformers import pipeline, set_seed
|
|
8 |
import psutil
|
9 |
import codecs
|
10 |
import streamlit.components.v1 as stc
|
11 |
-
import shutil
|
12 |
import pathlib
|
13 |
|
14 |
# st.set_page_config(page_title="Indonesian Story Generator")
|
@@ -29,10 +28,17 @@ MODELS = {
|
|
29 |
}
|
30 |
|
31 |
|
32 |
-
def stc_chatbot(
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
|
38 |
model = st.sidebar.selectbox('Model', (MODELS.keys()))
|
@@ -164,14 +170,5 @@ if model.find("Indonesian Literature") != -1:
|
|
164 |
session_state.text = None
|
165 |
elif model == "Indonesian Persona Chatbot":
|
166 |
st.subheader("Indonesian GPT-2 Persona Chatbot")
|
167 |
-
|
168 |
-
|
169 |
-
# We create a videos directory within the streamlit static asset directory
|
170 |
-
# and we write output files to it
|
171 |
-
ASSETS_PATH = STREAMLIT_STATIC_PATH/"gpt2-app"
|
172 |
-
if not ASSETS_PATH.is_dir():
|
173 |
-
ASSETS_PATH.mkdir()
|
174 |
-
shutil.copytree("app/css", ASSETS_PATH/"css")
|
175 |
-
shutil.copytree("app/js", ASSETS_PATH/"js")
|
176 |
-
|
177 |
-
stc_chatbot("app/chatbot.html")
|
|
|
8 |
import psutil
|
9 |
import codecs
|
10 |
import streamlit.components.v1 as stc
|
|
|
11 |
import pathlib
|
12 |
|
13 |
# st.set_page_config(page_title="Indonesian Story Generator")
|
|
|
28 |
}
|
29 |
|
30 |
|
31 |
+
def stc_chatbot(root_dir, width=700, height=900):
|
32 |
+
html_file = root_dir/"app/chatbot.html"
|
33 |
+
css_file = root_dir/"app/css/main.css"
|
34 |
+
js_file = root_dir/"app/js/main.js"
|
35 |
+
if css_file.exists() and js_file.exists():
|
36 |
+
html = codecs.open(html_file, "r").read()
|
37 |
+
css = codecs.open(css_file, "r").read()
|
38 |
+
js = codecs.open(js_file, "r").read()
|
39 |
+
html = html.replace('<link rel="stylesheet" href="css/main.css">', "<style>\n" + css + "\n</style>")
|
40 |
+
html = html.replace('<script src="js/main.js"></script>', "<script>\n" + js + "\n</script>")
|
41 |
+
stc.html(html, width=width, height=height, scrolling=True)
|
42 |
|
43 |
|
44 |
model = st.sidebar.selectbox('Model', (MODELS.keys()))
|
|
|
170 |
session_state.text = None
|
171 |
elif model == "Indonesian Persona Chatbot":
|
172 |
st.subheader("Indonesian GPT-2 Persona Chatbot")
|
173 |
+
root_dir = pathlib.Path(".")
|
174 |
+
stc_chatbot(root_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/chatbot.html
CHANGED
@@ -9,8 +9,8 @@
|
|
9 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
|
10 |
|
11 |
<title>Indonesian GPT2 Chatbot</title>
|
12 |
-
<link rel="stylesheet" href="
|
13 |
-
<script src="
|
14 |
</head>
|
15 |
<body onload="pageSetup();">
|
16 |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
|
|
|
9 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
|
10 |
|
11 |
<title>Indonesian GPT2 Chatbot</title>
|
12 |
+
<link rel="stylesheet" href="css/main.css">
|
13 |
+
<script src="js/main.js"></script>
|
14 |
</head>
|
15 |
<body onload="pageSetup();">
|
16 |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
|