Shreyas094 commited on
Commit
fda5a04
·
verified ·
1 Parent(s): 048efbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -10
app.py CHANGED
@@ -22,11 +22,7 @@ CLOUDFLARE_ACCOUNT_ID = os.environ.get("CLOUDFLARE_ACCOUNT_ID")
22
  CLOUDFLARE_AUTH_TOKEN = os.environ.get("CLOUDFLARE_AUTH_TOKEN")
23
 
24
  MODELS = [
25
- "Qwen/Qwen2-72B-Instruct",
26
- "google/gemma-2-9b",
27
  "microsoft/Phi-3-mini-4k-instruct",
28
- "Qwen/Qwen2-7B-Instruct",
29
- "mistralai/Mistral-Nemo-Instruct-2407",
30
  "mistralai/Mistral-7B-Instruct-v0.3",
31
  "mistralai/Mixtral-8x7B-Instruct-v0.1",
32
  "cloudflare/llama-3.1-8b-instruct" # Added Cloudflare Llama 3.1 model
@@ -41,7 +37,7 @@ llama_parser = LlamaParse(
41
  language="en",
42
  )
43
 
44
- def load_document(file: NamedTemporaryFile, parser: str = "pypdf") -> List[Document]:
45
  """Loads and splits the document into pages."""
46
  if parser == "pypdf":
47
  loader = PyPDFLoader(file.name)
@@ -84,7 +80,7 @@ def update_vectors(files, parser):
84
 
85
  return f"Vector store updated successfully. Processed {total_chunks} chunks from {len(files)} files using {parser}."
86
 
87
- def generate_chunked_response(prompt, model, max_tokens=1000, max_chunks=5, temperature=0.7):
88
  if model == "cloudflare/llama-3.1-8b-instruct":
89
  return generate_cloudflare_response(prompt, max_tokens, temperature)
90
 
@@ -176,7 +172,7 @@ class CitingSources(BaseModel):
176
  description="List of sources to cite. Should be an URL of the source."
177
  )
178
 
179
- def get_response_from_pdf(query, model, temperature=0.7):
180
  embed = get_embeddings()
181
  if os.path.exists("faiss_database"):
182
  database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
@@ -200,7 +196,7 @@ Do not include a list of sources in your response. [/INST]"""
200
 
201
  return clean_text
202
 
203
- def get_response_with_search(query, model, temperature=0.7):
204
  search_results = duckduckgo_search(query)
205
  context = "\n".join(f"{result['title']}\n{result['body']}\nSource: {result['href']}\n"
206
  for result in search_results if 'body' in result)
@@ -266,7 +262,7 @@ with gr.Blocks() as demo:
266
 
267
  with gr.Row():
268
  file_input = gr.Files(label="Upload your PDF documents", file_types=[".pdf"])
269
- parser_dropdown = gr.Dropdown(choices=["pypdf", "llamaparse"], label="Select PDF Parser", value="pypdf")
270
  update_button = gr.Button("Upload Document")
271
 
272
  update_output = gr.Textbox(label="Update Status")
@@ -278,7 +274,7 @@ with gr.Blocks() as demo:
278
 
279
  with gr.Row():
280
  model_dropdown = gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[2])
281
- temperature_slider = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature")
282
 
283
  submit = gr.Button("Submit")
284
 
 
22
  CLOUDFLARE_AUTH_TOKEN = os.environ.get("CLOUDFLARE_AUTH_TOKEN")
23
 
24
  MODELS = [
 
 
25
  "microsoft/Phi-3-mini-4k-instruct",
 
 
26
  "mistralai/Mistral-7B-Instruct-v0.3",
27
  "mistralai/Mixtral-8x7B-Instruct-v0.1",
28
  "cloudflare/llama-3.1-8b-instruct" # Added Cloudflare Llama 3.1 model
 
37
  language="en",
38
  )
39
 
40
+ def load_document(file: NamedTemporaryFile, parser: str = "llamaparse") -> List[Document]:
41
  """Loads and splits the document into pages."""
42
  if parser == "pypdf":
43
  loader = PyPDFLoader(file.name)
 
80
 
81
  return f"Vector store updated successfully. Processed {total_chunks} chunks from {len(files)} files using {parser}."
82
 
83
+ def generate_chunked_response(prompt, model, max_tokens=1000, max_chunks=5, temperature=0.2):
84
  if model == "cloudflare/llama-3.1-8b-instruct":
85
  return generate_cloudflare_response(prompt, max_tokens, temperature)
86
 
 
172
  description="List of sources to cite. Should be an URL of the source."
173
  )
174
 
175
+ def get_response_from_pdf(query, model, temperature=0.2):
176
  embed = get_embeddings()
177
  if os.path.exists("faiss_database"):
178
  database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
 
196
 
197
  return clean_text
198
 
199
+ def get_response_with_search(query, model, temperature=0.2):
200
  search_results = duckduckgo_search(query)
201
  context = "\n".join(f"{result['title']}\n{result['body']}\nSource: {result['href']}\n"
202
  for result in search_results if 'body' in result)
 
262
 
263
  with gr.Row():
264
  file_input = gr.Files(label="Upload your PDF documents", file_types=[".pdf"])
265
+ parser_dropdown = gr.Dropdown(choices=["pypdf", "llamaparse"], label="Select PDF Parser", value="llamaparse")
266
  update_button = gr.Button("Upload Document")
267
 
268
  update_output = gr.Textbox(label="Update Status")
 
274
 
275
  with gr.Row():
276
  model_dropdown = gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[2])
277
+ temperature_slider = gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature")
278
 
279
  submit = gr.Button("Submit")
280