Spaces:
Sleeping
Sleeping
Update pipeline.py
Browse files- pipeline.py +16 -3
pipeline.py
CHANGED
|
@@ -8,7 +8,7 @@ from langchain.embeddings import HuggingFaceEmbeddings
|
|
| 8 |
from langchain.vectorstores import FAISS
|
| 9 |
from langchain.chains import RetrievalQA
|
| 10 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, ManagedAgent, LiteLLMModel
|
| 11 |
-
#
|
| 12 |
|
| 13 |
# Import the chain builders from our separate files
|
| 14 |
from classification_chain import get_classification_chain
|
|
@@ -22,8 +22,21 @@ if not os.environ.get("GEMINI_API_KEY"):
|
|
| 22 |
if not os.environ.get("GROQ_API_KEY"):
|
| 23 |
os.environ["GROQ_API_KEY"] = getpass.getpass("Enter your GROQ API Key: ")
|
| 24 |
|
| 25 |
-
# 2) Load spaCy model for NER
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Function to extract the main topic using NER
|
| 29 |
def extract_main_topic(query: str) -> str:
|
|
|
|
| 8 |
from langchain.vectorstores import FAISS
|
| 9 |
from langchain.chains import RetrievalQA
|
| 10 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, ManagedAgent, LiteLLMModel
|
| 11 |
+
import subprocess # Import subprocess to run shell commands
|
| 12 |
|
| 13 |
# Import the chain builders from our separate files
|
| 14 |
from classification_chain import get_classification_chain
|
|
|
|
| 22 |
if not os.environ.get("GROQ_API_KEY"):
|
| 23 |
os.environ["GROQ_API_KEY"] = getpass.getpass("Enter your GROQ API Key: ")
|
| 24 |
|
| 25 |
+
# 2) Load spaCy model for NER and download the spaCy model if not already installed
|
| 26 |
+
def install_spacy_model():
|
| 27 |
+
try:
|
| 28 |
+
# Check if the model is already installed
|
| 29 |
+
spacy.load("en_core_web_sm")
|
| 30 |
+
print("spaCy model 'en_core_web_sm' is already installed.")
|
| 31 |
+
except OSError:
|
| 32 |
+
# If model is not installed, download it using subprocess
|
| 33 |
+
print("Downloading spaCy model 'en_core_web_sm'...")
|
| 34 |
+
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"], check=True)
|
| 35 |
+
print("spaCy model 'en_core_web_sm' downloaded successfully.")
|
| 36 |
+
|
| 37 |
+
# Call the function to install the spaCy model if needed
|
| 38 |
+
install_spacy_model()
|
| 39 |
+
|
| 40 |
|
| 41 |
# Function to extract the main topic using NER
|
| 42 |
def extract_main_topic(query: str) -> str:
|