Spaces:
Running
Running
Upgraded to Gradio 4.16.0. Guide for converting to exe added.
Browse files- .gitignore +6 -1
- README.md +1 -1
- app.py +4 -3
- funcs/helper_functions.py +5 -5
- how_to_create_exe_dist.txt +35 -0
- requirements.txt +1 -1
.gitignore
CHANGED
@@ -11,7 +11,12 @@
|
|
11 |
*.json
|
12 |
*.html
|
13 |
*.log
|
|
|
14 |
.ipynb_checkpoints/*
|
15 |
old_code/*
|
16 |
model/*
|
17 |
-
output_model/*
|
|
|
|
|
|
|
|
|
|
11 |
*.json
|
12 |
*.html
|
13 |
*.log
|
14 |
+
*.spec
|
15 |
.ipynb_checkpoints/*
|
16 |
old_code/*
|
17 |
model/*
|
18 |
+
output_model/*
|
19 |
+
data/*
|
20 |
+
build_deps/*
|
21 |
+
dist/*
|
22 |
+
build/*
|
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: π
|
|
4 |
colorFrom: red
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: true
|
10 |
license: apache-2.0
|
|
|
4 |
colorFrom: red
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.16.0
|
8 |
app_file: app.py
|
9 |
pinned: true
|
10 |
license: apache-2.0
|
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
-
# Dendrograms will not work with the latest version of scipy (1.12.0), so
|
2 |
-
#
|
|
|
3 |
|
4 |
import gradio as gr
|
5 |
import pandas as pd
|
@@ -42,7 +43,7 @@ with block:
|
|
42 |
with gr.Accordion("Clean data", open = False):
|
43 |
with gr.Row():
|
44 |
clean_text = gr.Dropdown(value = "No", choices=["Yes", "No"], multiselect=False, label="Clean data - remove html, numbers with > 2 digits, emails, postcodes (UK).")
|
45 |
-
drop_duplicate_text = gr.Dropdown(value = "No", choices=["Yes", "No"], multiselect=False, label="Remove duplicate text, drop < 10 char strings. May make
|
46 |
anonymise_drop = gr.Dropdown(value = "No", choices=["Yes", "No"], multiselect=False, label="Anonymise data on file load. Personal details are redacted - not 100% effective. This is slow!")
|
47 |
clean_btn = gr.Button("Clean data")
|
48 |
|
|
|
1 |
+
# Dendrograms will not work with the latest version of scipy (1.12.0), so run the following here/in your environment if you come across issues
|
2 |
+
# import os
|
3 |
+
# os.system("pip install scipy==1.11.4")
|
4 |
|
5 |
import gradio as gr
|
6 |
import pandas as pd
|
|
|
43 |
with gr.Accordion("Clean data", open = False):
|
44 |
with gr.Row():
|
45 |
clean_text = gr.Dropdown(value = "No", choices=["Yes", "No"], multiselect=False, label="Clean data - remove html, numbers with > 2 digits, emails, postcodes (UK).")
|
46 |
+
drop_duplicate_text = gr.Dropdown(value = "No", choices=["Yes", "No"], multiselect=False, label="Remove duplicate text, drop < 10 char strings. May make old embedding files incompatible due to differing lengths.")
|
47 |
anonymise_drop = gr.Dropdown(value = "No", choices=["Yes", "No"], multiselect=False, label="Anonymise data on file load. Personal details are redacted - not 100% effective. This is slow!")
|
48 |
clean_btn = gr.Button("Clean data")
|
49 |
|
funcs/helper_functions.py
CHANGED
@@ -30,12 +30,12 @@ class Logger:
|
|
30 |
def isatty(self):
|
31 |
return False
|
32 |
|
33 |
-
sys.stdout = Logger("output.log")
|
34 |
|
35 |
-
def read_logs():
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
|
41 |
def detect_file_type(filename):
|
|
|
30 |
def isatty(self):
|
31 |
return False
|
32 |
|
33 |
+
#sys.stdout = Logger("output.log")
|
34 |
|
35 |
+
# def read_logs():
|
36 |
+
# sys.stdout.flush()
|
37 |
+
# with open("output.log", "r") as f:
|
38 |
+
# return f.read()
|
39 |
|
40 |
|
41 |
def detect_file_type(filename):
|
how_to_create_exe_dist.txt
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
1. Create minimal environment to run the app in conda. E.g. 'conda create --name new_env'
|
2 |
+
|
3 |
+
2. Activate the environment 'conda activate new_env'
|
4 |
+
|
5 |
+
3. cd to this folder. Install packages from requirements.txt using 'pip install -r requirements.txt'
|
6 |
+
|
7 |
+
NOTE: for ensuring that spaCy models are loaded into the program correctly in requirements.txt, follow this guide: https://spacy.io/usage/models#models-download
|
8 |
+
|
9 |
+
6. If necessary, create hook- files to tell pyinstaller to include specific packages in the exe build. Examples are provided for gradio and en_core_web_sm (a spaCy model). Put these in the build_deps\ subfolder
|
10 |
+
|
11 |
+
7. pip install pyinstaller
|
12 |
+
|
13 |
+
8. In command line, cd to the folder that contains app.py.
|
14 |
+
|
15 |
+
9.Run the following, assuming you want to make one single .exe file (This helped me: https://github.com/pyinstaller/pyinstaller/issues/8108):
|
16 |
+
|
17 |
+
a) In command line: pyi-makespec --additional-hooks-dir="build_deps\\" --collect-data=gradio_client --collect-data=gradio --hidden-import pyarrow.vendored.version --onefile --name Bertopic_app_0.1 app.py
|
18 |
+
|
19 |
+
b) Open the created spec file in Notepad. Add the following to the end of the Analysis section then save:
|
20 |
+
|
21 |
+
a = Analysis(
|
22 |
+
...
|
23 |
+
module_collection_mode={
|
24 |
+
'gradio': 'py', # Collect gradio package as source .py files
|
25 |
+
}
|
26 |
+
)
|
27 |
+
|
28 |
+
c) Back in command line, run this: pyinstaller --clean --noconfirm Bertopic_app_0.1.spec
|
29 |
+
|
30 |
+
|
31 |
+
9. A 'dist' folder will be created with the executable inside along with all dependencies('dist\data_text_search').
|
32 |
+
|
33 |
+
10. In 'dist\data_text_search' try double clicking on the .exe file. After a short delay, the command prompt should inform you about the IP address of the app that is now running. Copy the IP address. **Do not close this window!**
|
34 |
+
|
35 |
+
11. In an Internet browser, navigate to the indicated IP address. The app should now be running in your browser window.
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
gradio==
|
2 |
transformers==4.37.1
|
3 |
accelerate==0.26.1
|
4 |
torch==2.1.2
|
|
|
1 |
+
gradio==4.16.0
|
2 |
transformers==4.37.1
|
3 |
accelerate==0.26.1
|
4 |
torch==2.1.2
|