Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
from PyPDF2 import PdfReader
|
3 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
4 |
-
from langchain_community.embeddings import HuggingFaceEmbeddings
|
5 |
from langchain.vectorstores import FAISS
|
6 |
from langchain.chains import RetrievalQA
|
7 |
from langchain.llms import HuggingFacePipeline
|
@@ -9,10 +9,18 @@ import torch
|
|
9 |
from transformers import pipeline
|
10 |
from langdetect import detect
|
11 |
|
12 |
-
# Load a smaller LLM
|
13 |
-
def load_llm():
|
14 |
model_name = "HuggingFaceH4/zephyr-7b-alpha" # Replace with your preferred model
|
15 |
-
pipe = pipeline(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
llm = HuggingFacePipeline(pipeline=pipe)
|
17 |
return llm
|
18 |
|
@@ -104,8 +112,14 @@ def main():
|
|
104 |
# Create vector store
|
105 |
vector_store = create_vector_store(chunks, indexing_method=indexing_method)
|
106 |
|
107 |
-
#
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
# Query translation options
|
111 |
query_method = st.selectbox(
|
|
|
1 |
import streamlit as st
|
2 |
from PyPDF2 import PdfReader
|
3 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
4 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
5 |
from langchain.vectorstores import FAISS
|
6 |
from langchain.chains import RetrievalQA
|
7 |
from langchain.llms import HuggingFacePipeline
|
|
|
9 |
from transformers import pipeline
|
10 |
from langdetect import detect
|
11 |
|
12 |
+
# Load a smaller LLM with customizable parameters
|
13 |
+
def load_llm(temperature, top_k, max_length):
|
14 |
model_name = "HuggingFaceH4/zephyr-7b-alpha" # Replace with your preferred model
|
15 |
+
pipe = pipeline(
|
16 |
+
"text-generation",
|
17 |
+
model=model_name,
|
18 |
+
torch_dtype=torch.float16,
|
19 |
+
device_map="auto",
|
20 |
+
temperature=temperature,
|
21 |
+
top_k=top_k,
|
22 |
+
max_length=max_length,
|
23 |
+
)
|
24 |
llm = HuggingFacePipeline(pipeline=pipe)
|
25 |
return llm
|
26 |
|
|
|
112 |
# Create vector store
|
113 |
vector_store = create_vector_store(chunks, indexing_method=indexing_method)
|
114 |
|
115 |
+
# LLM Parameters
|
116 |
+
st.sidebar.header("LLM Parameters")
|
117 |
+
temperature = st.sidebar.slider("Temperature", 0.1, 1.0, 0.7, help="Controls randomness in the output.")
|
118 |
+
top_k = st.sidebar.slider("Top-k", 1, 100, 50, help="Limits sampling to the top-k tokens.")
|
119 |
+
max_length = st.sidebar.slider("Max Length", 50, 500, 200, help="Maximum length of the generated response.")
|
120 |
+
|
121 |
+
# Load LLM with user-defined parameters
|
122 |
+
llm = load_llm(temperature=temperature, top_k=top_k, max_length=max_length)
|
123 |
|
124 |
# Query translation options
|
125 |
query_method = st.selectbox(
|