Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,13 +47,15 @@ def retrieve_thoughts(query, ):
|
|
| 47 |
df = pd.concat((df, pd.DataFrame([doc[1] for doc in docs_with_score], columns = ['score'])), axis = 1)
|
| 48 |
|
| 49 |
# TO-DO: What if user query doesn't match what we provide as documents
|
| 50 |
-
|
| 51 |
|
| 52 |
tier_1 = df
|
| 53 |
tier_2 = df[((df['score'] < 1) * (df["score"] > 0.8))]
|
| 54 |
|
| 55 |
tier_1
|
| 56 |
-
chunks_1 = tier_1.groupby(['title', 'url', ]).apply(lambda x: "\n...\n".join(x.sort_values('
|
|
|
|
|
|
|
| 57 |
tier_1_adjusted = tier_1.groupby(['title', 'url', ]).first().reset_index()[[ 'title', 'url']]
|
| 58 |
tier_1_adjusted['ref'] = range(1, len(tier_1_adjusted) + 1 )
|
| 59 |
tier_1_adjusted['content'] = chunks_1
|
|
@@ -64,6 +66,7 @@ def retrieve_thoughts(query, ):
|
|
| 64 |
|
| 65 |
# tier_1 = [doc[0] for doc in docs if ((doc[1] < 1))][:5]
|
| 66 |
# tier_2 = [doc[0] for doc in docs if ((doc[1] > 0.7)*(doc[1] < 1.5))][10:15]
|
|
|
|
| 67 |
|
| 68 |
return {'tier 1':tier_1_adjusted[:18], 'tier 2': tier_2_adjusted.loc[:5]}
|
| 69 |
|
|
|
|
| 47 |
df = pd.concat((df, pd.DataFrame([doc[1] for doc in docs_with_score], columns = ['score'])), axis = 1)
|
| 48 |
|
| 49 |
# TO-DO: What if user query doesn't match what we provide as documents
|
| 50 |
+
# df.sort_values("score", inplace = True)
|
| 51 |
|
| 52 |
tier_1 = df
|
| 53 |
tier_2 = df[((df['score'] < 1) * (df["score"] > 0.8))]
|
| 54 |
|
| 55 |
tier_1
|
| 56 |
+
chunks_1 = tier_1.groupby(['title', 'url', ]).apply(lambda x: "\n...\n".join(x.sort_values('score').iloc[:3].sort_values('id')['page_content'].values)).values
|
| 57 |
+
score = tier_1.groupby(['title', 'url', ]).apply(lambda x: x.sort_values('score').iloc[:3]['score'].mean()).values
|
| 58 |
+
|
| 59 |
tier_1_adjusted = tier_1.groupby(['title', 'url', ]).first().reset_index()[[ 'title', 'url']]
|
| 60 |
tier_1_adjusted['ref'] = range(1, len(tier_1_adjusted) + 1 )
|
| 61 |
tier_1_adjusted['content'] = chunks_1
|
|
|
|
| 66 |
|
| 67 |
# tier_1 = [doc[0] for doc in docs if ((doc[1] < 1))][:5]
|
| 68 |
# tier_2 = [doc[0] for doc in docs if ((doc[1] > 0.7)*(doc[1] < 1.5))][10:15]
|
| 69 |
+
tier_1_adjusted.sort_values("score", inplace = True)
|
| 70 |
|
| 71 |
return {'tier 1':tier_1_adjusted[:18], 'tier 2': tier_2_adjusted.loc[:5]}
|
| 72 |
|