Mary12 commited on
Commit
e7fb126
·
1 Parent(s): c7bc26e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -59
app.py CHANGED
@@ -58,72 +58,46 @@ def model(model_name):
58
  model_name = "timpal0l/mdeberta-v3-base-squad2"
59
  pipe = model(model_name)
60
 
61
- # def qa_result(context, question, file, pipe = pipe):
62
- # if file is not None:
63
- # allowed_types = [".pdf", ".txt", ".docx"]
64
- # extension = "." + file.name.split(".")[-1].lower()
65
- # if not extension in allowed_types:
66
- # text = "Խնդրում եմ ներբեռնել .pdf, .txt, կամ .docx տիպի ֆայլեր։"
67
- # else:
68
- # if extension == allowed_types[0]:
69
- # context = extract_text_from_pdf(file.name)
70
- # elif extension == allowed_types[1]:
71
- # context = extract_text_from_txt(file.name)
72
- # else:
73
- # context = extract_text_from_doc(file.name)
74
 
75
- # result = pipe(question=question, context=context)
76
- # answered = result['answer']
77
- # text = remove_references(answered)
78
 
79
- # elif file is None and len(context) == 0 and len(question) == 0:
80
- # text = "Որպեսզի ես կարողանամ քեզ օգնել, ինձ պիտի տրամադրես համապատասխան տեքստն կամ ֆայլն ու հարցերը։"
81
 
82
- # else:
83
- # if len(context) == 0 and len(question) == 0:
84
- # text = "Որպեսզի ես կարողանամ քեզ օգնել, ինձ պիտի տրամադրես համապատասխան տեքստն ու հարցերը։"
85
- # elif len(context) == 0:
86
- # text = "Ես չեմ կարողանա քեզ օգնել եթե ինձ չտրամադրես տեքստը"
87
- # elif len(context) == 0:
88
- # text = "Ես չեմ կարողանա քեզ օգնել եթե ինձ չտաս հարցդ"
89
- # else:
90
- # result = pipe(question=question, context=context)
91
- # answered = result['answer']
92
- # text = remove_references(answered)
93
- # text = text.replace('(', '', 1)
94
- # text = text.replace(',', '', len(text)-1)
95
-
96
- # return text.capitalize()
97
-
98
-
99
- def qa_result(context, question, file_name, file_extension, pipe=pipe):
100
- text = ""
101
-
102
- if len(context) == 0 or len(question) == 0:
103
- text = "Որպեսզի ես կարողանամ քեզ օգնել, ինձ պիտի տրամադրես համապատասխան տեքստը և հարցերը։"
104
  else:
105
- if file_extension not in [".pdf", ".txt", ".docx"]:
106
- text = "Խնդրում եմ ներբեռնել .pdf, .txt, կամ .docx տիպի ֆայլեր։"
107
- else:
108
- if file_extension == ".pdf":
109
- context = extract_text_from_pdf(file_name)
110
- elif file_extension == ".txt":
111
- context = extract_text_from_txt(file_name)
112
- else:
113
- context = extract_text_from_doc(file_name)
114
-
115
- result = pipe(question=question, context=context)
116
- answered = result['answer']
117
- text = remove_references(answered)
118
-
119
- text = text[1:] # Remove the first parenthesis
120
- if text.endswith(','):
121
- text = text[:-1] # Remove trailing comma
122
-
123
-
124
  return text.capitalize()
125
 
126
 
 
127
  theme = gr.themes.Soft().set(
128
  body_background_fill='*background_fill_secondary',
129
  body_text_color_subdued='*body_text_color',
 
58
  model_name = "timpal0l/mdeberta-v3-base-squad2"
59
  pipe = model(model_name)
60
 
61
+ def qa_result(context, question, file, pipe = pipe):
62
+ if file is not None:
63
+ allowed_types = [".pdf", ".txt", ".docx"]
64
+ extension = "." + file.name.split(".")[-1].lower()
65
+ if not extension in allowed_types:
66
+ text = "Խնդրում եմ ներբեռնել .pdf, .txt, կամ .docx տիպի ֆայլեր։"
67
+ else:
68
+ if extension == allowed_types[0]:
69
+ context = extract_text_from_pdf(file.name)
70
+ elif extension == allowed_types[1]:
71
+ context = extract_text_from_txt(file.name)
72
+ else:
73
+ context = extract_text_from_doc(file.name)
74
 
75
+ # result = pipe(question=question, context=context)
76
+ # answered = result['answer']
77
+ # text = remove_references(answered)
78
 
79
+ elif file is None and len(context) == 0 and len(question) == 0:
80
+ text = "Որպեսզի ես կարողանամ քեզ օգնել, ինձ պիտի տրամադրես համապատասխան տեքստն կամ ֆայլն ու հարցերը։"
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  else:
83
+ if len(context) == 0 and len(question) == 0:
84
+ text = "Որպեսզի ես կարողանամ քեզ օգնել, ինձ պիտի տրամադրես համապատասխան տեքստն ու հարցերը։"
85
+ elif len(context) == 0:
86
+ text = "Ես չեմ կարողանա քեզ օգնել եթե ինձ չտրամադրես տեքստը"
87
+ elif len(context) == 0:
88
+ text = "Ես չեմ կարողանա քեզ օգնել եթե ինձ չտաս հարցդ"
89
+ # else:
90
+
91
+ result = pipe(question=question, context=context)
92
+ answered = result['answer']
93
+ text = remove_references(answered)
94
+ text = text.replace('(', '', 1)
95
+ text = text.replace(',', '', len(text)-1)
96
+
 
 
 
 
 
97
  return text.capitalize()
98
 
99
 
100
+
101
  theme = gr.themes.Soft().set(
102
  body_background_fill='*background_fill_secondary',
103
  body_text_color_subdued='*body_text_color',