AI-trainer1 commited on
Commit
5a1dbb0
·
verified ·
1 Parent(s): 6a3519d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -98,11 +98,18 @@ class PDFQAProcessor:
98
 
99
  response = rag_chain.invoke({"input": question})
100
 
101
- final_response = response["answer"] + "\n\nSources\n\n"
102
 
103
- for info in response["context"]:
104
- final_response += info.page_content + "\nSource of Info: " + info.metadata['source'] + "\nAt Page No: " + info.metadata['page_label']+"\n\n"
105
 
 
 
 
 
 
 
 
106
  return final_response
107
  except Exception as e:
108
  return f"Error answering question: {str(e)}", None
@@ -117,7 +124,8 @@ with gr.Blocks(title="PDF QA Assistant") as demo:
117
 
118
  with gr.Tab("Ask Questions"):
119
  question_input = gr.Textbox(label="Your Question")
120
- answer_output = gr.Textbox(label="Answer", interactive=False)
 
121
  ask_btn = gr.Button("Ask Question")
122
 
123
  process_btn.click(
 
98
 
99
  response = rag_chain.invoke({"input": question})
100
 
101
+ # final_response = response["answer"] + "\n\nSources\n\n"
102
 
103
+ # for info in response["context"]:
104
+ # final_response += info.page_content + "\nSource of Info: " + info.metadata['source'] + "\nAt Page No: " + info.metadata['page_label']+"\n\n"
105
 
106
+ final_response = response["answer"] + "\n\n### Sources\n\n" # Changed to use markdown formatting
107
+ for info in response["context"]:
108
+ final_response += (
109
+ f"{info.page_content}<br>" # Changed to use markdown bold formatting
110
+ f"Source of Info: {info.metadata['source']}<br>"
111
+ f"At Page No: {info.metadata['page_label']}<br><br>"
112
+ )
113
  return final_response
114
  except Exception as e:
115
  return f"Error answering question: {str(e)}", None
 
124
 
125
  with gr.Tab("Ask Questions"):
126
  question_input = gr.Textbox(label="Your Question")
127
+ # answer_output = gr.Textbox(label="Answer", interactive=False)
128
+ answer_output = gr.Markdown(label="Answer")
129
  ask_btn = gr.Button("Ask Question")
130
 
131
  process_btn.click(