Akjava commited on
Commit
5d6dbe9
·
verified ·
1 Parent(s): 7564c84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -135,6 +135,10 @@ Search Query: transformer architectures
135
  User Question: What is the history of the transformer model?
136
  Search Query: transformer model history
137
  """
 
 
 
 
138
  def to_query(provider,question):
139
  print(f"<question> = {question}")
140
  print(f"<query sytem> = {query_system}")
@@ -165,7 +169,7 @@ Search Query:
165
  returns_streaming_generator=False,
166
  print_output=False,
167
  )
168
- return result
169
  except Exception as e:
170
  # Custom exception handling
171
  raise CustomExceptionHandling(e, sys) from e
@@ -232,7 +236,7 @@ Document:
232
  retriever_system="""
233
  You are an AI assistant that answers questions based on below retrievered documents.
234
 
235
- Document:
236
  ---
237
  %s
238
  ---
@@ -297,7 +301,7 @@ Answer:
297
  # Create a chat interface
298
  demo = gr.ChatInterface(
299
  respond,
300
- examples=[["What is the Transformer?"], ["Tell me About Huggingface."], ["How to upload dataset?"]],
301
  additional_inputs_accordion=gr.Accordion(
302
  label="⚙️ Parameters", open=False, render=False
303
  ),
 
135
  User Question: What is the history of the transformer model?
136
  Search Query: transformer model history
137
  """
138
+ def clean_text(text):
139
+ cleaned = re.sub(r'[^\x00-\x7F]+', '', text) # Remove non-ASCII chars
140
+ cleaned = re.sub(r'[^a-zA-Z0-9_\- ]', '', cleaned) #Then your original rule
141
+ return cleaned
142
  def to_query(provider,question):
143
  print(f"<question> = {question}")
144
  print(f"<query sytem> = {query_system}")
 
169
  returns_streaming_generator=False,
170
  print_output=False,
171
  )
172
+ return clean_text(result)
173
  except Exception as e:
174
  # Custom exception handling
175
  raise CustomExceptionHandling(e, sys) from e
 
236
  retriever_system="""
237
  You are an AI assistant that answers questions based on below retrievered documents.
238
 
239
+ Documents:
240
  ---
241
  %s
242
  ---
 
301
  # Create a chat interface
302
  demo = gr.ChatInterface(
303
  respond,
304
+ examples=[["What is the Diffuser?"], ["Tell me About Huggingface."], ["How to upload dataset?"]],
305
  additional_inputs_accordion=gr.Accordion(
306
  label="⚙️ Parameters", open=False, render=False
307
  ),