agoyal496 commited on
Commit
72390f6
·
1 Parent(s): 6dee266

Update error handling

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -13,19 +13,22 @@ retriever = Retrieval(model_name=embedding_model_name)
13
 
14
  llm_model_name = "gpt-4o-mini"
15
  # Settting up LLMGenerator
16
- llm_generator = LLMGeneration(llm_model_name=llm_model_name)
17
 
18
- def set_api_key(api_key):
19
- os.environ['OPENAI_API_KEY'] = api_key
 
 
 
20
 
21
  def process_inputs(api_key:str, pdf_file, questions: str):
22
 
23
  # Setup Api KEY
24
  set_api_key(api_key)
 
25
 
26
  if pdf_file is None:
27
- raise Exception("Blaf")
28
-
29
 
30
  # Parsing the pdf
31
  doc_handler = DocParsing(file_path=pdf_file.name,model_name=embedding_model_name)
@@ -34,7 +37,11 @@ def process_inputs(api_key:str, pdf_file, questions: str):
34
  # Create vector store
35
  retriever.create_vector_store(chunks=docs)
36
 
 
 
37
 
 
 
38
  output_dict = {}
39
  questions_list = questions.strip().split('\n')
40
  for question in questions_list:
 
13
 
14
  llm_model_name = "gpt-4o-mini"
15
  # Settting up LLMGenerator
16
+ llm_generator = None
17
 
18
+ def set_api_key(api_key: str):
19
+ if api_key.strip():
20
+ os.environ['OPENAI_API_KEY'] = api_key
21
+ else:
22
+ raise gr.Error("Please provide a valid API key")
23
 
24
  def process_inputs(api_key:str, pdf_file, questions: str):
25
 
26
  # Setup Api KEY
27
  set_api_key(api_key)
28
+
29
 
30
  if pdf_file is None:
31
+ raise gr.Error("Please upload a pdf file")
 
32
 
33
  # Parsing the pdf
34
  doc_handler = DocParsing(file_path=pdf_file.name,model_name=embedding_model_name)
 
37
  # Create vector store
38
  retriever.create_vector_store(chunks=docs)
39
 
40
+ # LLM Generator
41
+ llm_generator = LLMGeneration(llm_model_name=llm_model_name)
42
 
43
+ if not questions.strip():
44
+ raise gr.Error("Please provide valid set of questions")
45
  output_dict = {}
46
  questions_list = questions.strip().split('\n')
47
  for question in questions_list: