Abid Ali Awan commited on
Commit
2987ac4
·
1 Parent(s): 5ca6388

added qa part

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -62,8 +62,8 @@ def load_files(file_path: str):
62
  # Respond function
63
  def respond(message, history):
64
  # Use the preloaded LLM
65
- query_engine = vector_index.as_chat_engine(llm=llm)
66
- streaming_response = query_engine.stream_chat(message)
67
  partial_text = ""
68
  for new_text in streaming_response.response_gen:
69
  partial_text += new_text
@@ -71,6 +71,13 @@ def respond(message, history):
71
  yield partial_text
72
 
73
 
 
 
 
 
 
 
 
74
  # UI Setup
75
  with gr.Blocks(
76
  theme=gr.themes.Default(
@@ -105,7 +112,7 @@ with gr.Blocks(
105
  # Set up Gradio interactions
106
  btn.click(fn=load_files, inputs=file_input, outputs=output)
107
  clear.click(
108
- lambda: [None, None],
109
  outputs=[file_input, output],
110
  )
111
 
 
62
  # Respond function
63
  def respond(message, history):
64
  # Use the preloaded LLM
65
+ query_engine = vector_index.as_query_engine(streaming=True, llm=llm)
66
+ streaming_response = query_engine.query(message)
67
  partial_text = ""
68
  for new_text in streaming_response.response_gen:
69
  partial_text += new_text
 
71
  yield partial_text
72
 
73
 
74
+ # Clear function
75
+ def clear_state():
76
+ global vector_index
77
+ vector_index = None
78
+ return [None, None, None]
79
+
80
+
81
  # UI Setup
82
  with gr.Blocks(
83
  theme=gr.themes.Default(
 
112
  # Set up Gradio interactions
113
  btn.click(fn=load_files, inputs=file_input, outputs=output)
114
  clear.click(
115
+ fn=clear_state, # Use the clear_state function
116
  outputs=[file_input, output],
117
  )
118