root
commited on
Commit
·
1d62827
1
Parent(s):
c0d9b94
ss
Browse files- app.py +18 -0
- explanation_generator.py +20 -0
- requirements.txt +4 -3
app.py
CHANGED
@@ -18,6 +18,24 @@ import io
|
|
18 |
import PyPDF2
|
19 |
from docx import Document
|
20 |
import csv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
from explanation_generator import ExplanationGenerator
|
22 |
|
23 |
# Download NLTK resources
|
|
|
18 |
import PyPDF2
|
19 |
from docx import Document
|
20 |
import csv
|
21 |
+
import sys
|
22 |
+
|
23 |
+
# Add Replicate class workaround
|
24 |
+
class Replicate(torch.nn.Module):
|
25 |
+
"""Workaround class for missing Replicate in NV-Embed and Qwen models"""
|
26 |
+
def __init__(self, module, num_replicas=1):
|
27 |
+
super().__init__()
|
28 |
+
self.module = module
|
29 |
+
self.num_replicas = num_replicas
|
30 |
+
|
31 |
+
def forward(self, *args, **kwargs):
|
32 |
+
return self.module(*args, **kwargs)
|
33 |
+
|
34 |
+
# Add the class to Python's built-ins
|
35 |
+
sys.modules["transformers.models.nvembed.modeling_nvembed"].Replicate = Replicate
|
36 |
+
sys.modules["transformers.models.qwen2.modeling_qwen2"] = type('', (), {})
|
37 |
+
sys.modules["transformers.models.qwen2.modeling_qwen2"].Replicate = Replicate
|
38 |
+
|
39 |
from explanation_generator import ExplanationGenerator
|
40 |
|
41 |
# Download NLTK resources
|
explanation_generator.py
CHANGED
@@ -9,6 +9,26 @@ import torch
|
|
9 |
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
10 |
import os
|
11 |
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Load QwQ model at initialization time
|
14 |
print("Loading Qwen/QwQ-32B model with 4-bit quantization...")
|
|
|
9 |
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
10 |
import os
|
11 |
import re
|
12 |
+
import sys
|
13 |
+
|
14 |
+
# Add Replicate class workaround if not already defined
|
15 |
+
try:
|
16 |
+
from transformers.models.qwen2.modeling_qwen2 import Replicate
|
17 |
+
except (ImportError, AttributeError):
|
18 |
+
class Replicate(torch.nn.Module):
|
19 |
+
"""Workaround class for missing Replicate in Qwen models"""
|
20 |
+
def __init__(self, module, num_replicas=1):
|
21 |
+
super().__init__()
|
22 |
+
self.module = module
|
23 |
+
self.num_replicas = num_replicas
|
24 |
+
|
25 |
+
def forward(self, *args, **kwargs):
|
26 |
+
return self.module(*args, **kwargs)
|
27 |
+
|
28 |
+
# Add the class to modules
|
29 |
+
if "transformers.models.qwen2.modeling_qwen2" not in sys.modules:
|
30 |
+
sys.modules["transformers.models.qwen2.modeling_qwen2"] = type('', (), {})
|
31 |
+
sys.modules["transformers.models.qwen2.modeling_qwen2"].Replicate = Replicate
|
32 |
|
33 |
# Load QwQ model at initialization time
|
34 |
print("Loading Qwen/QwQ-32B model with 4-bit quantization...")
|
requirements.txt
CHANGED
@@ -4,7 +4,7 @@ PyPDF2==3.0.1
|
|
4 |
python-docx==1.0.1
|
5 |
spacy==3.7.2
|
6 |
https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.7.0/en_core_web_sm-3.7.0.tar.gz
|
7 |
-
transformers==4.
|
8 |
torch==2.1.2
|
9 |
nltk==3.8.1
|
10 |
faiss-cpu==1.7.4
|
@@ -14,7 +14,8 @@ plotly==5.18.0
|
|
14 |
pandas==2.1.3
|
15 |
numpy==1.24.3
|
16 |
tqdm==4.66.1
|
17 |
-
huggingface-hub
|
18 |
-
einops
|
19 |
bitsandbytes>=0.41.0
|
20 |
accelerate>=0.23.0
|
|
|
|
4 |
python-docx==1.0.1
|
5 |
spacy==3.7.2
|
6 |
https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.7.0/en_core_web_sm-3.7.0.tar.gz
|
7 |
+
transformers==4.36.2
|
8 |
torch==2.1.2
|
9 |
nltk==3.8.1
|
10 |
faiss-cpu==1.7.4
|
|
|
14 |
pandas==2.1.3
|
15 |
numpy==1.24.3
|
16 |
tqdm==4.66.1
|
17 |
+
huggingface-hub==0.25.0
|
18 |
+
einops
|
19 |
bitsandbytes>=0.41.0
|
20 |
accelerate>=0.23.0
|
21 |
+
optimum>=1.13.1
|