aryn25 commited on
Commit
b6398e4
Β·
verified Β·
1 Parent(s): 08fdf5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -1,15 +1,15 @@
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
@@ -37,12 +37,13 @@ def create_vector_store(region_topic):
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:
 
1
  # Cultural Bias Explorer in Language Models
2
  # ----------------------------------------
3
+ # This Python project uses LangChain + HuggingFaceEndpoint 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 huggingface_hub 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_huggingface import HuggingFaceEndpoint
13
  from langchain.chains import RetrievalQA
14
  from langchain.text_splitter import RecursiveCharacterTextSplitter
15
  import os
 
37
  return vectorstore
38
 
39
  # ------------------ MAIN LOGIC ------------------
40
+ # Set your Hugging Face token in HF settings or as an env variable
41
+ # No need to manually set it here if using Hugging Face Spaces securely
42
 
43
+ llm = HuggingFaceEndpoint(
44
+ repo_id="HuggingFaceH4/zephyr-7b-beta", # free-access model
45
+ temperature=0.7,
46
+ max_new_tokens=512
47
  )
48
 
49
  for region in REGIONS: