Skip to content

Commit 5a3b1b1

Browse files
Merge pull request #57 from seanpedrick-case/dev
Upgraded packages and added compatibility with Gradio 6
2 parents c1117f4 + 5d29a37 commit 5a3b1b1

13 files changed

+339
-283
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ feedback/*
1616
test_code/*
1717
unsloth_compiled_cache/*
1818
.vscode/*
19+
llm_topic_modelling.egg-info/*
1920
input/
2021
output/
2122
logs/

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ test_code/*
1717
config/*
1818
tmp/*
1919
unsloth_compiled_cache/*
20-
.vscode/*
20+
.vscode/*
21+
llm_topic_modelling.egg-info/*

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
---
22
title: Large language model topic modelling
3-
emoji: 📝
3+
emoji: 📚
44
colorFrom: purple
55
colorTo: yellow
66
sdk: gradio
7+
sdk_version: 6.0.2
78
app_file: app.py
89
pinned: true
910
license: agpl-3.0
11+
short_description: Create thematic summaries for open text data
1012
---
1113

1214
# Large language model topic modelling
1315

14-
Version: 0.5.1
16+
Version: 0.5.2
1517

1618
Extract topics and summarise outputs using Large Language Models (LLMs, Gemma 3 4b/GPT-OSS 20b if local (see tools/config.py to modify), Gemini, Azure, or AWS Bedrock models (e.g. Claude, Nova models). The app will query the LLM with batches of responses to produce summary tables, which are then compared iteratively to output a table with the general topics, subtopics, topic sentiment, and a topic summary. Instructions on use can be found in the README.md file. You can try out examples by clicking on one of the example datasets on the main app page, which will show you example outputs from a local model run. API keys for AWS, Azure, and Gemini services can be entered on the settings page (note that Gemini has a free public API).
1719

app.py

Lines changed: 118 additions & 115 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "llm_topic_modelling"
7-
version = "0.5.1"
7+
version = "0.5.2"
88
description = "Generate thematic summaries from open text in tabular data files with a large language model."
99
requires-python = ">=3.10"
1010
readme = "README.md"
@@ -50,55 +50,59 @@ classifiers = [
5050
"Programming Language :: Python :: 3.13",
5151
]
5252

53-
dependencies = [
54-
"pandas==2.3.3",
55-
"gradio==5.49.1",
56-
"transformers==4.57.1",
53+
dependencies = [
54+
"gradio==6.0.2",
55+
"transformers==4.57.2",
5756
"spaces==0.42.1",
58-
"boto3==1.40.72",
59-
"pyarrow==21.0.0",
60-
"openpyxl==3.1.5",
61-
"markdown==3.7",
62-
"tabulate==0.9.0",
63-
"lxml==5.3.0",
64-
"google-genai==1.50.0",
65-
"openai==2.2.0",
66-
"html5lib==1.1",
67-
"beautifulsoup4==4.12.3",
68-
"rapidfuzz==3.13.0",
69-
"python-dotenv==1.1.0"
57+
"boto3==1.42.1",
58+
"pandas<=2.3.3",
59+
"pyarrow>=21.0.0",
60+
"openpyxl>=3.1.5",
61+
"markdown>=3.7",
62+
"tabulate>=0.9.0",
63+
"lxml>=5.3.0",
64+
"google-genai<=1.52.0",
65+
"openai<=2.8.1",
66+
"html5lib>=1.1",
67+
"beautifulsoup4>=4.12.3",
68+
"rapidfuzz>=3.13.0",
69+
"python-dotenv>=1.1.0"
7070
]
7171

7272
[project.optional-dependencies]
7373
dev = ["pytest"]
7474
test = ["pytest", "pytest-cov"]
7575

7676
# Extra dependencies for VLM models
77-
# For torch you should use --index-url https://download.pytorch.org/whl/cu124. Additionally installs the unsloth package
77+
# For torch you should use --index-url https://download.pytorch.org/whl/cu128. Additionally installs the unsloth package
7878
torch = [
79-
"torch==2.6.0",
80-
"accelerate==1.11.0",
81-
"bitsandbytes==0.48.2",
82-
"unsloth==2025.9.4",
83-
"unsloth_zoo==2025.9.5",
84-
"timm==1.0.19"
79+
"torch<=2.9.1",
80+
"torchvision",
81+
"accelerate",
82+
"bitsandbytes",
83+
"unsloth==2025.11.6",
84+
"unsloth_zoo==2025.11.6",
85+
"timm",
86+
"xformers"
8587
]
8688

87-
# If you want to install llama-cpp-python in GPU mode, use cmake.args="-DGGML_CUDA=on" . If that doesn't work, try specific wheels for your system, e.g. for Linux: See files in https://github.com/abetlen/llama-cpp-python/releases/tag/v0.3.16-cu124 . More details on installation here: https://llama-cpp-python.readthedocs.io/en/latest
89+
# If you want to install llama-cpp-python in GPU mode, use cmake.args="-DGGML_CUDA=on" . If that doesn't work, try specific wheels for your system, e.g. for Linux see files in https://github.com/JamePeng/llama-cpp-python/releases. More details on installation here: https://llama-cpp-python.readthedocs.io/en/latest
8890
llamacpp = [
89-
"llama-cpp-python==0.3.16",
91+
"llama-cpp-python>=0.3.16",
9092
]
9193

9294
# Run Gradio as an mcp server
9395
mcp = [
94-
"gradio[mcp]==5.49.1"
96+
"gradio[mcp]==6.0.2"
9597
]
9698

9799
[project.urls]
98100
Homepage = "https://github.com/seanpedrick-case/llm_topic_modelling"
99101
repository = "https://github.com/seanpedrick-case/llm_topic_modelling"
100102

101-
103+
[tool.setuptools]
104+
packages = ["tools"]
105+
py-modules = ["app"]
102106

103107
# Configuration for Ruff linter:
104108
[tool.ruff]

requirements.txt

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
# Note that this requirements file is optimised for Hugging Face spaces / Python 3.10. Please use requirements_no_local.txt for installation without local model inference (simplest approach to get going). Please use requirements_cpu.txt for CPU instances and requirements_gpu.txt for GPU instances using Python 3.11
2-
pandas==2.3.3
3-
gradio==5.49.1
4-
transformers==4.57.1
2+
gradio==6.0.2
3+
transformers==4.57.2
54
spaces==0.42.1
6-
boto3==1.40.72
7-
pyarrow==21.0.0
8-
openpyxl==3.1.5
9-
markdown==3.7
10-
tabulate==0.9.0
11-
lxml==5.3.0
12-
google-genai==1.50.0
13-
openai==2.2.0
14-
html5lib==1.1
15-
beautifulsoup4==4.12.3
16-
rapidfuzz==3.13.0
17-
python-dotenv==1.1.0
5+
boto3>=1.42.1
6+
pandas>=2.3.3
7+
pyarrow>=21.0.0
8+
openpyxl>=3.1.5
9+
markdown>=3.7
10+
tabulate>=0.9.0
11+
lxml>=5.3.0
12+
google-genai>=1.52.0
13+
openai>=2.8.1
14+
html5lib>=1.1
15+
beautifulsoup4>=4.12.3
16+
rapidfuzz>=3.13.0
17+
python-dotenv>=1.1.0
1818
# GPU (for huggingface instance)
1919
# Torch/Unsloth and llama-cpp-python
2020
# Latest compatible with CUDA 12.4
21-
torch==2.6.0 --extra-index-url https://download.pytorch.org/whl/cu124
22-
unsloth[cu124-torch260]==2025.9.4
23-
unsloth_zoo==2025.9.5
24-
timm==1.0.19
25-
# llama-cpp-python direct wheel link for GPU compatible version 3.16 for use with Python 3.10 and Hugging Face
26-
https://github.com/abetlen/llama-cpp-python/releases/download/v0.3.16-cu124/llama_cpp_python-0.3.16-cp310-cp310-linux_x86_64.whl
21+
torch<=2.9.1 --extra-index-url https://download.pytorch.org/whl/cu128
22+
unsloth[cu128-torch280]<=2025.11.6
23+
unsloth_zoo<=2025.11.6
24+
timm
25+
# llama-cpp-python direct wheel link for GPU compatible version 3.17 for use with Python 3.10 and Hugging Face
26+
https://github.com/JamePeng/llama-cpp-python/releases/download/v0.3.17-cu128-Basic-linux-20251202/llama_cpp_python-0.3.17-cp310-cp310-linux_x86_64.whl
27+
#https://github.com/abetlen/llama-cpp-python/releases/download/v0.3.16-cu124/llama_cpp_python-0.3.16-cp310-cp310-linux_x86_64.whl
2728

2829

requirements_cpu.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
pandas==2.3.3
2-
gradio==5.49.1
3-
transformers==4.56.0
1+
gradio==6.0.2
2+
transformers==4.57.2
43
spaces==0.42.1
5-
boto3==1.40.48
6-
pyarrow==21.0.0
7-
openpyxl==3.1.5
8-
markdown==3.7
9-
tabulate==0.9.0
10-
lxml==5.3.0
11-
google-genai==1.50.0
12-
openai==2.2.0
13-
html5lib==1.1
14-
beautifulsoup4==4.12.3
15-
rapidfuzz==3.13.0
16-
python-dotenv==1.1.0
17-
torch==2.8.0 --extra-index-url https://download.pytorch.org/whl/cpu
4+
pandas>=2.3.3
5+
boto3>=1.42.1
6+
pyarrow>=21.0.0
7+
openpyxl>=3.1.5
8+
markdown>=3.7
9+
tabulate>=0.9.0
10+
lxml>=5.3.0
11+
google-genai>=1.52.0
12+
openai>=2.8.1
13+
html5lib>=1.1
14+
beautifulsoup4>=4.12.3
15+
rapidfuzz>=3.13.0
16+
python-dotenv>=1.1.0
17+
torch<=2.9.1 --extra-index-url https://download.pytorch.org/whl/cpu
1818
llama-cpp-python==0.3.16 -C cmake.args="-DGGML_BLAS=ON;-DGGML_BLAS_VENDOR=OpenBLAS"
1919
# Direct wheel links if above doesn't work
2020
# I have created CPU Linux, Python 3.11 compatible wheels:

requirements_gpu.txt

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
1-
pandas==2.3.3
2-
gradio==5.49.1
3-
transformers==4.57.1
1+
2+
gradio==6.0.2
3+
transformers==4.57.2
44
spaces==0.42.1
5-
boto3==1.40.72
6-
pyarrow==21.0.0
7-
openpyxl==3.1.5
8-
markdown==3.7
9-
tabulate==0.9.0
10-
lxml==5.3.0
11-
google-genai==1.50.0
12-
openai==2.2.0
13-
html5lib==1.1
14-
beautifulsoup4==4.12.3
15-
rapidfuzz==3.13.0
16-
python-dotenv==1.1.0
5+
boto3>=1.42.1
6+
pandas>=2.3.3
7+
pyarrow>=21.0.0
8+
openpyxl>=3.1.5
9+
markdown>=3.7
10+
tabulate>=0.9.0
11+
lxml>=5.3.0
12+
google-genai>=1.52.0
13+
openai>=2.8.1
14+
html5lib>=1.1
15+
beautifulsoup4>=4.12.3
16+
rapidfuzz>=3.13.0
17+
python-dotenv>=1.1.0
1718
# Torch/Unsloth
1819
# Latest compatible with CUDA 12.4
19-
torch==2.6.0 --extra-index-url https://download.pytorch.org/whl/cu124
20-
unsloth[cu124-torch260]==2025.9.4 # Refer here for more details on installation: https://pypi.org/project/unsloth
21-
unsloth_zoo==2025.9.5
20+
torch<=2.9.1 --extra-index-url https://download.pytorch.org/whl/cu128
21+
unsloth[cu128-torch280]<=2025.11.6 # Refer here for more details on installation: https://pypi.org/project/unsloth
22+
unsloth_zoo<=2025.11.6
2223
# Additional for Windows and CUDA 12.4 older GPUS (RTX 3x or similar):
2324
#triton-windows<3.3
24-
timm==1.0.19
25+
timm
2526
# Llama CPP Python
26-
llama-cpp-python==0.3.16 -C cmake.args="-DGGML_CUDA=on"
27-
# If below doesn't work, try specific wheels for your system:
28-
# For Linux:
29-
# See files in https://github.com/abetlen/llama-cpp-python/releases/tag/v0.3.16-cu124 for different python versions
30-
# Python 3.11 compatible wheel:
31-
# https://github.com/abetlen/llama-cpp-python/releases/download/v0.3.16-cu124/llama_cpp_python-0.3.16-cp311-cp311-linux_x86_64.whl
32-
# For Windows, not available at above link. I have made a GPU Windows wheel for Python 3.11:
33-
# https://github.com/seanpedrick-case/llama-cpp-python-whl-builder/releases/download/v0.1.0/llama_cpp_python-0.3.16-cp311-cp311-win_amd64.whl
27+
llama-cpp-python>=0.3.16 -C cmake.args="-DGGML_CUDA=on"
28+
# If above doesn't work, try specific wheels for your system, see files in https://github.com/JamePeng/llama-cpp-python/releases for different python versions

requirements_lightweight.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# This requirements file is optimised for AWS ECS using Python 3.11 alongside the Dockerfile, without local torch and llama-cpp-python. For AWS ECS, torch and llama-cpp-python are optionally installed in the main Dockerfile
2-
pandas==2.3.3
3-
gradio==5.49.1
4-
transformers==4.57.1
2+
gradio==6.0.2
3+
transformers==4.57.2
54
spaces==0.42.1
6-
boto3==1.40.72
7-
pyarrow==21.0.0
8-
openpyxl==3.1.5
9-
markdown==3.7
10-
tabulate==0.9.0
11-
lxml==5.3.0
12-
google-genai==1.50.0
13-
openai==2.2.0
14-
html5lib==1.1
15-
beautifulsoup4==4.12.3
16-
rapidfuzz==3.13.0
17-
python-dotenv==1.1.0
5+
boto3>=1.42.1
6+
pandas>=2.3.3
7+
pyarrow>=21.0.0
8+
openpyxl>=3.1.5
9+
markdown>=3.7
10+
tabulate>=0.9.0
11+
lxml>=5.3.0
12+
google-genai>=1.52.0
13+
openai>=2.8.1
14+
html5lib>=1.1
15+
beautifulsoup4>=4.12.3
16+
rapidfuzz>=3.13.0
17+
python-dotenv>=1.1.0

tools/config.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ def convert_string_to_boolean(value: str) -> bool:
261261
model_source = list()
262262

263263
CHOSEN_LOCAL_MODEL_TYPE = get_or_create_env_var("CHOSEN_LOCAL_MODEL_TYPE", "Qwen 3 4B") # Gemma 3 1B # "Gemma 2b" # "Gemma 3 4B"
264+
print("CHOSEN_LOCAL_MODEL_TYPE:", CHOSEN_LOCAL_MODEL_TYPE)
264265

265266
if RUN_LOCAL_MODEL == "1" and CHOSEN_LOCAL_MODEL_TYPE:
266267
model_full_names.append(CHOSEN_LOCAL_MODEL_TYPE)
@@ -329,6 +330,8 @@ def update_model_choice_config(default_model_source, model_name_map):
329330
# If you are using a system with low VRAM, you can set this to True to reduce the memory requirements
330331
LOW_VRAM_SYSTEM = get_or_create_env_var('LOW_VRAM_SYSTEM', 'False')
331332

333+
MULTIMODAL_PROMPT_FORMAT = get_or_create_env_var('MULTIMODAL_PROMPT_FORMAT', 'False')
334+
332335
if LOW_VRAM_SYSTEM == 'True':
333336
print("Using settings for low VRAM system")
334337
USE_LLAMA_CPP = get_or_create_env_var('USE_LLAMA_CPP', 'True')
@@ -340,14 +343,18 @@ def update_model_choice_config(default_model_source, model_name_map):
340343

341344
USE_LLAMA_CPP = get_or_create_env_var('USE_LLAMA_CPP', 'True') # Llama.cpp or transformers with unsloth
342345

346+
LOCAL_REPO_ID = get_or_create_env_var("LOCAL_REPO_ID", "")
347+
LOCAL_MODEL_FILE = get_or_create_env_var("LOCAL_MODEL_FILE", "")
348+
LOCAL_MODEL_FOLDER = get_or_create_env_var("LOCAL_MODEL_FOLDER", "")
349+
343350
GEMMA2_REPO_ID = get_or_create_env_var("GEMMA2_2B_REPO_ID", "unsloth/gemma-2-it-GGUF")
344351
GEMMA2_REPO_TRANSFORMERS_ID = get_or_create_env_var("GEMMA2_2B_REPO_TRANSFORMERS_ID", "unsloth/gemma-2-2b-it-bnb-4bit")
345352
if USE_LLAMA_CPP == "False": GEMMA2_REPO_ID = GEMMA2_REPO_TRANSFORMERS_ID
346353
GEMMA2_MODEL_FILE = get_or_create_env_var("GEMMA2_2B_MODEL_FILE", "gemma-2-2b-it.q8_0.gguf")
347354
GEMMA2_MODEL_FOLDER = get_or_create_env_var("GEMMA2_2B_MODEL_FOLDER", "model/gemma")
348355

349356
GEMMA3_4B_REPO_ID = get_or_create_env_var("GEMMA3_4B_REPO_ID", "unsloth/gemma-3-4b-it-qat-GGUF")
350-
GEMMA3_4B_REPO_TRANSFORMERS_ID = get_or_create_env_var("GEMMA3_4B_REPO_TRANSFORMERS_ID", "https://huggingface.co/unsloth/gemma-3-4b-it-bnb-4bit" )
357+
GEMMA3_4B_REPO_TRANSFORMERS_ID = get_or_create_env_var("GEMMA3_4B_REPO_TRANSFORMERS_ID", "unsloth/gemma-3-4b-it-bnb-4bit" )
351358
if USE_LLAMA_CPP == "False": GEMMA3_4B_REPO_ID = GEMMA3_4B_REPO_TRANSFORMERS_ID
352359
GEMMA3_4B_MODEL_FILE = get_or_create_env_var("GEMMA3_4B_MODEL_FILE", "gemma-3-4b-it-qat-UD-Q4_K_XL.gguf")
353360
GEMMA3_4B_MODEL_FOLDER = get_or_create_env_var("GEMMA3_4B_MODEL_FOLDER", "model/gemma3_4b")
@@ -392,11 +399,13 @@ def update_model_choice_config(default_model_source, model_name_map):
392399
LOCAL_REPO_ID = GEMMA3_4B_REPO_ID
393400
LOCAL_MODEL_FILE = GEMMA3_4B_MODEL_FILE
394401
LOCAL_MODEL_FOLDER = GEMMA3_4B_MODEL_FOLDER
402+
MULTIMODAL_PROMPT_FORMAT = "True"
395403

396404
elif CHOSEN_LOCAL_MODEL_TYPE == "Gemma 3 12B":
397405
LOCAL_REPO_ID = GEMMA3_12B_REPO_ID
398406
LOCAL_MODEL_FILE = GEMMA3_12B_MODEL_FILE
399407
LOCAL_MODEL_FOLDER = GEMMA3_12B_MODEL_FOLDER
408+
MULTIMODAL_PROMPT_FORMAT = "True"
400409

401410
elif CHOSEN_LOCAL_MODEL_TYPE == "Qwen 3 4B":
402411
LOCAL_REPO_ID = QWEN3_4B_REPO_ID
@@ -419,9 +428,17 @@ def update_model_choice_config(default_model_source, model_name_map):
419428
LOCAL_MODEL_FOLDER = GRANITE_4_3B_MODEL_FOLDER
420429

421430
elif not CHOSEN_LOCAL_MODEL_TYPE:
431+
print("No local model type chosen")
422432
LOCAL_REPO_ID = ""
423433
LOCAL_MODEL_FILE = ""
424434
LOCAL_MODEL_FOLDER = ""
435+
else:
436+
print("CHOSEN_LOCAL_MODEL_TYPE not found")
437+
LOCAL_REPO_ID = ""
438+
LOCAL_MODEL_FILE = ""
439+
LOCAL_MODEL_FOLDER = ""
440+
441+
print("LOCAL_REPO_ID:", LOCAL_REPO_ID)
425442

426443

427444
USE_SPECULATIVE_DECODING = get_or_create_env_var("USE_SPECULATIVE_DECODING", "False")
@@ -456,7 +473,7 @@ def update_model_choice_config(default_model_source, model_name_map):
456473
LLM_CONTEXT_LENGTH = int(get_or_create_env_var('LLM_CONTEXT_LENGTH', '24576'))
457474
LLM_SAMPLE = get_or_create_env_var('LLM_SAMPLE', 'True')
458475
LLM_STOP_STRINGS = get_or_create_env_var('LLM_STOP_STRINGS', r"['\n\n\n\n\n\n']")
459-
MULTIMODAL_PROMPT_FORMAT = get_or_create_env_var('MULTIMODAL_PROMPT_FORMAT', 'False')
476+
460477
SPECULATIVE_DECODING = get_or_create_env_var('SPECULATIVE_DECODING', 'False')
461478
NUM_PRED_TOKENS = int(get_or_create_env_var('NUM_PRED_TOKENS', '2'))
462479
K_QUANT_LEVEL = get_or_create_env_var('K_QUANT_LEVEL', '') # 2 = q4_0, 8 = q8_0, 4 = fp16

0 commit comments

Comments
 (0)