Vera-ZWY commited on
Commit
be6a0c9
·
verified ·
1 Parent(s): 3992a53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -51
app.py CHANGED
@@ -44,7 +44,12 @@ def stream_chat_with_rag(
44
  # Call the API with the user's process_query
45
  question = message
46
  #answer = client.predict(question=question, api_name="/run_graph")
47
- answer = client.predict(question=question,selected_document=client_name, api_name="/process_query")
 
 
 
 
 
48
 
49
  # Debugging: Print the raw response
50
  print("Raw answer from API:")
@@ -114,33 +119,28 @@ def format_relevant_documents(relevant_docs: list):
114
  return formatted_docs.strip()
115
 
116
 
117
- # ------------------------------------- Core CNI APP ----------------------------------------------------------------------------------
118
- # Function to handle PDF processing API call
119
- def process_pdf(pdf_file, client_name):
120
- return client.predict(
121
- pdf_file=handle_file(pdf_file),
122
- #client_name=client_name, # Hardcoded client name
123
- api_name="/process_pdf"
124
- )[1] # Return only the result string
125
 
126
- # # Function to handle search API call
127
- # def search_api(query):
128
- # return client.predict(query=query, api_name="/search_with_confidence")
129
 
130
- # Function to handle RAG API call
131
- def rag_api(question, client_name):
132
- return client.predict(question=question,selected_document=client_name, api_name="/get_answer")
133
 
134
- def delete_index():
135
- result = client.predict(api_name="/delete_index")
136
- return result
137
 
138
 
139
- #-------------------------------------- View PDF ----------------------------------------------------------------------------------
140
- def view_pdf(pdf):
141
- result = client.predict(api_name="/view_pdf_name")
142
- return result
143
-
144
 
145
  #-------------------------------------- UX & Gradio -------------------------------------------------------------------------------
146
 
@@ -168,7 +168,7 @@ with gr.Blocks(css=CSS) as demo:
168
  chatbot=chatbot,
169
  additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
170
  additional_inputs=[
171
- gr.Dropdown(client_name,value="primo",label="Select Client", render=False,allow_custom_value=True),
172
  gr.Textbox(
173
  value="You are an expert assistant",
174
  label="System Prompt",
@@ -234,34 +234,34 @@ with gr.Blocks(css=CSS) as demo:
234
  )
235
 
236
 
237
- with gr.Tab("Process PDF"):
238
- pdf_input = gr.File(label="Upload PDF File")
239
- #select_client_dropdown = gr.Dropdown(client_name, value="rosariarossi", label="Select or Type Client", allow_custom_value=True)
240
- pdf_output = gr.Textbox(label="PDF Result", interactive=False)
241
 
242
- pdf_button = gr.Button("Process PDF")
243
- pdf_button.click(
244
- process_pdf,
245
- inputs=[pdf_input], # Pass both PDF and client name is not required
246
- outputs=pdf_output
247
- )
248
-
249
- with gr.Tab("Answer with RAG"):
250
- question_input = gr.Textbox(label="Enter Question for RAG")
251
- answer_with_rag_select_client_dropdown = gr.Dropdown(client_name, value="primo", label="Select or Type Client", allow_custom_value=True)
252
- rag_output = gr.Textbox(label="RAG Answer Result", interactive=False)
253
-
254
- rag_button = gr.Button("Get Answer")
255
- rag_button.click(
256
- rag_api,
257
- inputs=[question_input,answer_with_rag_select_client_dropdown ],
258
- outputs=rag_output
259
- )
260
- with gr.Tab(label="Manage Files"):
261
- with gr.Column():
262
- delete_index_button = gr.Button("Delete All Files")
263
- delete_index_textout = gr.Textbox(label="Deleted Files and Refresh Result")
264
- delete_index_button.click(fn=delete_index, inputs=[],outputs=[delete_index_textout])
265
 
266
  # Launch the app
267
  if __name__ == "__main__":
 
44
  # Call the API with the user's process_query
45
  question = message
46
  #answer = client.predict(question=question, api_name="/run_graph")
47
+ answer = client.predict(
48
+ query="Hello!!",
49
+ context="Hello!!",
50
+ election_year="2016 Election",
51
+ api_name="/process_query"
52
+ )
53
 
54
  # Debugging: Print the raw response
55
  print("Raw answer from API:")
 
119
  return formatted_docs.strip()
120
 
121
 
122
+ # # ------------------------------------- Core CNI APP ----------------------------------------------------------------------------------
123
+ # # Function to handle PDF processing API call
124
+ # def process_pdf(pdf_file, client_name):
125
+ # return client.predict(
126
+ # pdf_file=handle_file(pdf_file),
127
+ # #client_name=client_name, # Hardcoded client name
128
+ # api_name="/process_pdf"
129
+ # )[1] # Return only the result string
130
 
131
+ # # # Function to handle search API call
132
+ # # def search_api(query):
133
+ # # return client.predict(query=query, api_name="/search_with_confidence")
134
 
135
+ # # Function to handle RAG API call
136
+ # def rag_api(question, client_name):
137
+ # return client.predict(question=question,selected_document=client_name, api_name="/get_answer")
138
 
139
+ # def delete_index():
140
+ # result = client.predict(api_name="/delete_index")
141
+ # return result
142
 
143
 
 
 
 
 
 
144
 
145
  #-------------------------------------- UX & Gradio -------------------------------------------------------------------------------
146
 
 
168
  chatbot=chatbot,
169
  additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
170
  additional_inputs=[
171
+ gr.Dropdown(client_name,value="2016 Election",label="Select Election year", render=False,allow_custom_value=True),
172
  gr.Textbox(
173
  value="You are an expert assistant",
174
  label="System Prompt",
 
234
  )
235
 
236
 
237
+ # with gr.Tab("Process PDF"):
238
+ # pdf_input = gr.File(label="Upload PDF File")
239
+ # #select_client_dropdown = gr.Dropdown(client_name, value="rosariarossi", label="Select or Type Client", allow_custom_value=True)
240
+ # pdf_output = gr.Textbox(label="PDF Result", interactive=False)
241
 
242
+ # pdf_button = gr.Button("Process PDF")
243
+ # pdf_button.click(
244
+ # process_pdf,
245
+ # inputs=[pdf_input], # Pass both PDF and client name is not required
246
+ # outputs=pdf_output
247
+ # )
248
+
249
+ # with gr.Tab("Answer with RAG"):
250
+ # question_input = gr.Textbox(label="Enter Question for RAG")
251
+ # answer_with_rag_select_client_dropdown = gr.Dropdown(client_name, value="primo", label="Select or Type Client", allow_custom_value=True)
252
+ # rag_output = gr.Textbox(label="RAG Answer Result", interactive=False)
253
+
254
+ # rag_button = gr.Button("Get Answer")
255
+ # rag_button.click(
256
+ # rag_api,
257
+ # inputs=[question_input,answer_with_rag_select_client_dropdown ],
258
+ # outputs=rag_output
259
+ # )
260
+ # with gr.Tab(label="Manage Files"):
261
+ # with gr.Column():
262
+ # delete_index_button = gr.Button("Delete All Files")
263
+ # delete_index_textout = gr.Textbox(label="Deleted Files and Refresh Result")
264
+ # delete_index_button.click(fn=delete_index, inputs=[],outputs=[delete_index_textout])
265
 
266
  # Launch the app
267
  if __name__ == "__main__":