Spaces:
Runtime error
Runtime error
samarthagarwal23
commited on
Commit
•
854c812
1
Parent(s):
b5b0fd2
Update app.py
Browse files
app.py
CHANGED
@@ -65,9 +65,11 @@ def cstr(s, color='black'):
|
|
65 |
return "<text style=color:{}>{}</text>".format(color, s)
|
66 |
def cstr_bold(s, color='black'):
|
67 |
return "<text style=color:{}><b>{}</b></text>".format(color, s)
|
|
|
|
|
68 |
|
69 |
-
def print_colored(text, start_idx, end_idx):
|
70 |
-
a = cstr(' '.join([text[:start_idx], cstr_bold(text[start_idx:end_idx], color='red'), text[end_idx:]]), color='black')
|
71 |
#a = colored(text[:start_idx]) + colored(text[start_idx:end_idx], 'red', 'on_yellow') + colored(text[end_idx:])
|
72 |
return a
|
73 |
|
@@ -85,7 +87,8 @@ def final_qa_pipeline(file, query):
|
|
85 |
if len(lvl1) > 0:
|
86 |
fnl_rank = qa_ranker(query, [l["docs"] for l in lvl1], top_k_ranker)
|
87 |
#return (fnl_rank[0]["answer"], str(np.round(100*fnl_rank[0]["score"],2))+"%" , fnl_rank[0]['doc'])
|
88 |
-
return (print_colored(fnl_rank[0]['doc'], fnl_rank[0]['start'], fnl_rank[0]['end']), str(np.round(100*fnl_rank[0]["score"],2))+"%"
|
|
|
89 |
#for fnl_ in fnl_rank:
|
90 |
# print("\n")
|
91 |
# print_colored(fnl_['doc'], fnl_['start'], fnl_['end'])
|
|
|
65 |
return "<text style=color:{}>{}</text>".format(color, s)
|
66 |
def cstr_bold(s, color='black'):
|
67 |
return "<text style=color:{}><b>{}</b></text>".format(color, s)
|
68 |
+
def cstr_break(s, color='black'):
|
69 |
+
return "<text style=color:{}>{}<br></text>".format(color, s)
|
70 |
|
71 |
+
def print_colored(text, start_idx, end_idx, confidence):
|
72 |
+
a = cstr_break(' '.join(cstr(' '.join([text[:start_idx], cstr_bold(text[start_idx:end_idx], color='red'), text[end_idx:]]), color='black'), 'Confidence: {}'.format(confidence), color='black)
|
73 |
#a = colored(text[:start_idx]) + colored(text[start_idx:end_idx], 'red', 'on_yellow') + colored(text[end_idx:])
|
74 |
return a
|
75 |
|
|
|
87 |
if len(lvl1) > 0:
|
88 |
fnl_rank = qa_ranker(query, [l["docs"] for l in lvl1], top_k_ranker)
|
89 |
#return (fnl_rank[0]["answer"], str(np.round(100*fnl_rank[0]["score"],2))+"%" , fnl_rank[0]['doc'])
|
90 |
+
#return (print_colored(fnl_rank[0]['doc'], fnl_rank[0]['start'], fnl_rank[0]['end']), str(np.round(100*fnl_rank[0]["score"],2))+"%"
|
91 |
+
return (print_colored(fnl_rank[0]['doc'], fnl_rank[0]['start'], fnl_rank[0]['end'], str(np.round(100*fnl_rank[0]["score"],2))+"%") )
|
92 |
#for fnl_ in fnl_rank:
|
93 |
# print("\n")
|
94 |
# print_colored(fnl_['doc'], fnl_['start'], fnl_['end'])
|