Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,18 @@
|
|
1 |
# Cultural Bias Explorer in Language Models
|
2 |
# ----------------------------------------
|
3 |
-
# This Python project uses LangChain +
|
4 |
# by retrieving answers to the same prompts using region-specific document bases.
|
5 |
|
6 |
# Install necessary packages before running:
|
7 |
-
# pip install langchain langchain-community
|
8 |
|
9 |
from langchain_community.document_loaders import WikipediaLoader
|
10 |
from langchain.embeddings import HuggingFaceEmbeddings
|
11 |
from langchain.vectorstores import FAISS
|
12 |
-
from langchain.llms import
|
13 |
from langchain.chains import RetrievalQA
|
14 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
|
15 |
|
16 |
# ------------------ CONFIG ------------------
|
17 |
REGIONS = ['India', 'United States']
|
@@ -36,7 +37,13 @@ def create_vector_store(region_topic):
|
|
36 |
return vectorstore
|
37 |
|
38 |
# ------------------ MAIN LOGIC ------------------
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
for region in REGIONS:
|
42 |
print(f"\n=== REGION: {region.upper()} ===")
|
|
|
1 |
# Cultural Bias Explorer in Language Models
|
2 |
# ----------------------------------------
|
3 |
+
# This Python project uses LangChain + HuggingFaceHub to explore cultural bias
|
4 |
# by retrieving answers to the same prompts using region-specific document bases.
|
5 |
|
6 |
# Install necessary packages before running:
|
7 |
+
# pip install langchain langchain-community faiss-cpu sentence-transformers unstructured wikipedia
|
8 |
|
9 |
from langchain_community.document_loaders import WikipediaLoader
|
10 |
from langchain.embeddings import HuggingFaceEmbeddings
|
11 |
from langchain.vectorstores import FAISS
|
12 |
+
from langchain.llms import HuggingFaceHub
|
13 |
from langchain.chains import RetrievalQA
|
14 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
15 |
+
import os
|
16 |
|
17 |
# ------------------ CONFIG ------------------
|
18 |
REGIONS = ['India', 'United States']
|
|
|
37 |
return vectorstore
|
38 |
|
39 |
# ------------------ MAIN LOGIC ------------------
|
40 |
+
# Set your HF token as environment variable or directly in the constructor (not recommended for security)
|
41 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "your_hf_token_here" # Replace with your actual token
|
42 |
+
|
43 |
+
llm = HuggingFaceHub(
|
44 |
+
repo_id="mistralai/Mistral-7B-Instruct-v0.1",
|
45 |
+
model_kwargs={"temperature": 0.7, "max_new_tokens": 512}
|
46 |
+
)
|
47 |
|
48 |
for region in REGIONS:
|
49 |
print(f"\n=== REGION: {region.upper()} ===")
|