Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,26 +60,29 @@ pipe = model(model_name)
|
|
| 60 |
|
| 61 |
def qa_result(context, question, file, pipe = pipe):
|
| 62 |
if file is not None:
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
if not extension in allowed_types:
|
| 66 |
-
text = "Խնդրում եմ ներբեռնել .pdf, .txt, կամ .docx տիպի ֆայլեր։"
|
| 67 |
else:
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
else:
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
# text = remove_references(answered)
|
| 79 |
|
| 80 |
-
|
|
|
|
| 81 |
text = "Որպեսզի ես կարողանամ քեզ օգնել, ինձ պիտի տրամադրես համապատասխան տեքստն կամ ֆայլն ու հարցերը։"
|
| 82 |
-
|
| 83 |
else:
|
| 84 |
if len(context) == 0 and len(question) == 0:
|
| 85 |
text = "Որպեսզի ես կարողանամ քեզ օգնել, ինձ պիտի տրամադրես համապատասխան տեքստն ու հարցերը։"
|
|
|
|
| 60 |
|
| 61 |
def qa_result(context, question, file, pipe = pipe):
|
| 62 |
if file is not None:
|
| 63 |
+
if len(question) == 0:
|
| 64 |
+
text = "Ես չեմ կարողանա քեզ օգնել եթե ինձ չտաս հարցդ"
|
|
|
|
|
|
|
| 65 |
else:
|
| 66 |
+
allowed_types = [".pdf", ".txt", ".docx"]
|
| 67 |
+
extension = "." + file.name.split(".")[-1].lower()
|
| 68 |
+
if not extension in allowed_types:
|
| 69 |
+
text = "Խնդրում եմ ներբեռնել .pdf, .txt, կամ .docx տիպի ֆայլեր։"
|
| 70 |
else:
|
| 71 |
+
if extension == allowed_types[0]:
|
| 72 |
+
context = extract_text_from_pdf(file.name)
|
| 73 |
+
elif extension == allowed_types[1]:
|
| 74 |
+
context = extract_text_from_txt(file.name)
|
| 75 |
+
else:
|
| 76 |
+
context = extract_text_from_pdf(file.name)
|
| 77 |
+
result = pipe(question=question, context=context)
|
| 78 |
+
answered = result['answer']
|
| 79 |
+
text = remove_references(answered)
|
| 80 |
|
| 81 |
# text = remove_references(answered)
|
| 82 |
|
| 83 |
+
else:
|
| 84 |
+
if file is None and len(context) == 0 and len(question) == 0:
|
| 85 |
text = "Որպեսզի ես կարողանամ քեզ օգնել, ինձ պիտի տրամադրես համապատասխան տեքստն կամ ֆայլն ու հարցերը։"
|
|
|
|
| 86 |
else:
|
| 87 |
if len(context) == 0 and len(question) == 0:
|
| 88 |
text = "Որպեսզի ես կարողանամ քեզ օգնել, ինձ պիտի տրամադրես համապատասխան տեքստն ու հարցերը։"
|