Walid-Ahmed commited on
Commit
4d2c093
·
verified ·
1 Parent(s): c97500f

Deal with different encodings

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
3
 
4
  # Initialize the question-answering pipeline
5
  qa_pipeline = pipeline("question-answering")
@@ -12,8 +13,15 @@ def answer_question(context, question):
12
 
13
  def process(context_file, question):
14
  # Read the context from the uploaded file
15
- with open(context_file.name, 'r') as file:
16
- context = file.read()
 
 
 
 
 
 
 
17
 
18
  answer = answer_question(context, question)
19
  return answer
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import chardet
4
 
5
  # Initialize the question-answering pipeline
6
  qa_pipeline = pipeline("question-answering")
 
13
 
14
  def process(context_file, question):
15
  # Read the context from the uploaded file
16
+
17
+ #with open(context_file.name, 'r') as file:
18
+ #context = file.read()
19
+ with open(context_file.name, 'rb') as file:
20
+ raw_data = file.read()
21
+ result = chardet.detect(raw_data)
22
+ encoding = result['encoding']
23
+ context = raw_data.decode(encoding, errors='replace') # Replace errors with placeholder
24
+
25
 
26
  answer = answer_question(context, question)
27
  return answer