Spaces:
Runtime error
Runtime error
Update app.py
Browse files123458 unmodified lines14151617181920212223242526272829303132333435364 unmodified lines414243444546import gradio as grimport osfrom langchain_community.document_loaders import PyPDFLoaderfrom langchain_community.vectorstores import FAISSfrom langchain.text_splitter import RecursiveCharacterTextSplitter8 unmodified lineswarnings.warn = warnwarnings.filterwarnings('ignore')from dotenv import load_dotenvload_dotenv()from langchain.prompts import PromptTemplatefrom langchain_huggingface import (HuggingFaceEmbeddings,HuggingFaceEndpoint,)from langchain.schema.runnable import RunnablePassthroughfrom langchain.schema.output_parser import StrOutputParser# --- 1) CONFIG / SAFETY ---if not os.getenv("HUGGINGFACEHUB_API_TOKEN"):print("HUGGINGFACEHUB_API_TOKEN not found. Add it to your Space secrets.")raise SystemExit(1)## LLM - Using an open-source model from Hugging Facedef get_llm():4 unmodified linesrepo_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"llm = HuggingFaceHub(repo_id=repo_id,model_kwargs={"temperature": 0.1, "max_length": 512})return llm12348 unmodified lines131415161718192021224 unmodified lines272829303132333435import gradio as grfrom langchain_community.document_loaders import PyPDFLoaderfrom langchain_community.vectorstores import FAISSfrom langchain.text_splitter import RecursiveCharacterTextSplitter8 unmodified lineswarnings.warn = warnwarnings.filterwarnings('ignore')# Set your Hugging Face API token here.# For deployment on Hugging Face, you can set this as an environment variable.import osos.environ["HUGGINGFACEHUB_API_TOKEN"] = "hf_YOUR_HUGGINGFACE_TOKEN"## LLM - Using an open-source model from Hugging Facedef get_llm():4 unmodified linesrepo_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"llm = HuggingFaceHub(repo_id=repo_id,# The 'task' parameter is required to specify the model's function.# This fixes the 'Value error, Got invalid task None' error.task="text-generation",model_kwargs={"temperature": 0.1, "max_length": 512})return llm
app.py+7-18