jchen8000 commited on
Commit
6b268d2
·
verified ·
1 Parent(s): 029c170

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -20
app.py CHANGED
@@ -105,14 +105,12 @@ def load_sample_pdf():
105
 
106
  return "PDF(s) indexed successfully!"
107
 
108
- last_relevant_info_state = gr.State("")
109
 
110
  def format_docs(docs):
111
  return "\n\n".join(doc.page_content for doc in docs)
112
 
113
  def generate_response(query, history, model, temperature, max_tokens, top_p, seed):
114
- global last_relevant_info_state # Declare global to modify the state value
115
-
116
  if vector_store is None:
117
  return "Please upload and index a PDF at the Indexing tab."
118
 
@@ -126,7 +124,6 @@ def generate_response(query, history, model, temperature, max_tokens, top_p, see
126
 
127
  docs = retriever.invoke(query)
128
  relevant_info = format_docs(docs)
129
- last_relevant_info_state.value = relevant_info
130
 
131
  rag_chain = (
132
  {"context": retriever | format_docs, "question": RunnablePassthrough()}
@@ -137,10 +134,7 @@ def generate_response(query, history, model, temperature, max_tokens, top_p, see
137
 
138
  response = rag_chain.invoke(query)
139
 
140
- return relevant_info
141
-
142
- def get_relevant_info(state):
143
- return state # The state's value is what we want to display
144
 
145
  additional_inputs = [
146
  gr.Dropdown(choices=["llama-3.3-70b-versatile", "llama-3.1-8b-instant", "llama3-70b-8192", "llama3-8b-8192", "mixtral-8x7b-32768", "gemma2-9b-it"], value="gemma2-9b-it", label="Model"),
@@ -175,18 +169,14 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
175
  # additional_outputs=[relevant_info],
176
  cache_examples=False,
177
  )
178
- with gr.Column():
179
- retrieve_button = gr.Button("Retrieve Relevant Info")
180
- relevant_info = gr.Textbox(
181
- label="Retrieved Information",
182
- interactive=False,
183
- lines=20,
184
- )
185
- retrieve_button.click(
186
- fn=get_relevant_info,
187
- inputs=[gr_last_relevant_info_state], # Input is the state component
188
- outputs=[relevant_info] # Output updates the relevant_info textbox
189
- )
190
 
191
  # Launch the Gradio app
192
  demo.launch(share=True)
 
105
 
106
  return "PDF(s) indexed successfully!"
107
 
 
108
 
109
  def format_docs(docs):
110
  return "\n\n".join(doc.page_content for doc in docs)
111
 
112
  def generate_response(query, history, model, temperature, max_tokens, top_p, seed):
113
+
 
114
  if vector_store is None:
115
  return "Please upload and index a PDF at the Indexing tab."
116
 
 
124
 
125
  docs = retriever.invoke(query)
126
  relevant_info = format_docs(docs)
 
127
 
128
  rag_chain = (
129
  {"context": retriever | format_docs, "question": RunnablePassthrough()}
 
134
 
135
  response = rag_chain.invoke(query)
136
 
137
+ return response
 
 
 
138
 
139
  additional_inputs = [
140
  gr.Dropdown(choices=["llama-3.3-70b-versatile", "llama-3.1-8b-instant", "llama3-70b-8192", "llama3-8b-8192", "mixtral-8x7b-32768", "gemma2-9b-it"], value="gemma2-9b-it", label="Model"),
 
169
  # additional_outputs=[relevant_info],
170
  cache_examples=False,
171
  )
172
+ # with gr.Column():
173
+ # retrieve_button = gr.Button("Retrieve Relevant Info")
174
+ # relevant_info = gr.Textbox(
175
+ # label="Retrieved Information",
176
+ # interactive=False,
177
+ # lines=20,
178
+ # )
179
+
 
 
 
 
180
 
181
  # Launch the Gradio app
182
  demo.launch(share=True)