Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import easyocr
|
3 |
import numpy as np
|
4 |
-
from transformers import
|
5 |
|
6 |
class OCRProcessor:
|
7 |
def __init__(self):
|
@@ -14,17 +14,13 @@ class OCRProcessor:
|
|
14 |
except Exception as e:
|
15 |
return f"خطا در پردازش OCR: {str(e)}"
|
16 |
|
17 |
-
class
|
18 |
def __init__(self):
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
tokenizer=model_name
|
25 |
-
)
|
26 |
-
except Exception as e:
|
27 |
-
raise RuntimeError(f"خطا در بارگذاری مدل پرسش و پاسخ: {str(e)}")
|
28 |
|
29 |
def answer_question(self, context: str, question: str) -> str:
|
30 |
if not context.strip() or not question.strip():
|
@@ -39,7 +35,7 @@ class PersianQAModel:
|
|
39 |
return f"خطا در مدل پرسش و پاسخ: {str(e)}"
|
40 |
|
41 |
ocr_processor = OCRProcessor()
|
42 |
-
qa_model =
|
43 |
|
44 |
def pipeline_fn(image, question):
|
45 |
context = ocr_processor.extract_text(image)
|
|
|
1 |
import gradio as gr
|
2 |
import easyocr
|
3 |
import numpy as np
|
4 |
+
from transformers import pipeline
|
5 |
|
6 |
class OCRProcessor:
|
7 |
def __init__(self):
|
|
|
14 |
except Exception as e:
|
15 |
return f"خطا در پردازش OCR: {str(e)}"
|
16 |
|
17 |
+
class MultilingualQAModel:
|
18 |
def __init__(self):
|
19 |
+
self.qa_pipeline = pipeline(
|
20 |
+
"question-answering",
|
21 |
+
model="deepset/roberta-base-squad2",
|
22 |
+
tokenizer="deepset/roberta-base-squad2"
|
23 |
+
)
|
|
|
|
|
|
|
|
|
24 |
|
25 |
def answer_question(self, context: str, question: str) -> str:
|
26 |
if not context.strip() or not question.strip():
|
|
|
35 |
return f"خطا در مدل پرسش و پاسخ: {str(e)}"
|
36 |
|
37 |
ocr_processor = OCRProcessor()
|
38 |
+
qa_model = MultilingualQAModel()
|
39 |
|
40 |
def pipeline_fn(image, question):
|
41 |
context = ocr_processor.extract_text(image)
|