Spaces:
Sleeping
Sleeping
Deal with different encodings
Browse files
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 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|