Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
|
|
|
|
3 |
|
4 |
|
5 |
st.set_page_config(page_title="SEARCH IATI",layout='wide')
|
@@ -7,8 +9,52 @@ st.title("SEARCH IATI Database")
|
|
7 |
var=st.text_input("write keyword")
|
8 |
title = var.replace(' ','+')
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
button=st.button("search")
|
12 |
|
|
|
|
|
13 |
if button :
|
14 |
-
st.write(
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from langchain_text_splitters import TokenTextSplitter
|
4 |
+
from langchain.docstore.document import Document
|
5 |
|
6 |
|
7 |
st.set_page_config(page_title="SEARCH IATI",layout='wide')
|
|
|
9 |
var=st.text_input("write keyword")
|
10 |
title = var.replace(' ','+')
|
11 |
|
12 |
+
def create_chunks(text):
|
13 |
+
text_splitter = TokenTextSplitter(chunk_size=500, chunk_overlap=0)
|
14 |
+
texts = text_splitter.split_text(text)
|
15 |
+
return texts
|
16 |
+
|
17 |
+
def get_chunks():
|
18 |
+
orgas_df = pd.read_csv("iati_files/project_orgas.csv")
|
19 |
+
region_df = pd.read_csv("iati_files/project_region.csv")
|
20 |
+
sector_df = pd.read_csv("iati_files/project_sector.csv")
|
21 |
+
status_df = pd.read_csv("iati_files/project_status.csv")
|
22 |
+
texts_df = pd.read_csv("iati_files/project_texts.csv")
|
23 |
+
|
24 |
+
projects_df = pd.merge(orgas_df, region_df, on='iati_id', how='inner')
|
25 |
+
projects_df = pd.merge(projects_df, sector_df, on='iati_id', how='inner')
|
26 |
+
projects_df = pd.merge(projects_df, status_df, on='iati_id', how='inner')
|
27 |
+
projects_df = pd.merge(projects_df, texts_df, on='iati_id', how='inner')
|
28 |
+
giz_df = projects_df[projects_df.client.str.contains('bmz')].reset_index(drop=True)
|
29 |
+
|
30 |
+
giz_df.drop(columns= ['orga_abbreviation', 'client',
|
31 |
+
'orga_full_name', 'country',
|
32 |
+
'country_flag', 'crs_5_code', 'crs_3_code',
|
33 |
+
'sgd_pred_code'], inplace=True)
|
34 |
+
|
35 |
+
giz_df['text_size'] = giz_df.apply(lambda x: len((x['title_main'] + x['description_main']).split()), axis=1)
|
36 |
+
giz_df['chunks'] = giz_df.apply(lambda x:create_chunks(x['title_main'] + x['description_main']),axis=1)
|
37 |
+
giz_df = giz_df.explode(column=['chunks'], ignore_index=True)
|
38 |
+
|
39 |
+
|
40 |
+
placeholder= []
|
41 |
+
for i in range(len(giz_df)):
|
42 |
+
placeholder.append(Document(page_content= giz_df.loc[i,'chunks'],
|
43 |
+
metadata={"iati_id": giz_df.loc[i,'iati_id'],
|
44 |
+
"iati_orga_id":giz_df.loc[i,'iati_orga_id'],
|
45 |
+
"country_name":str(giz_df.loc[i,'country_name']),
|
46 |
+
"crs_5_name": giz_df.loc[i,'crs_5_name'],
|
47 |
+
"crs_3_name": giz_df.loc[i,'crs_3_name'],
|
48 |
+
"sgd_pred_str":giz_df.loc[i,'sgd_pred_str'],
|
49 |
+
"status":giz_df.loc[i,'status'],
|
50 |
+
"title_main":giz_df.loc[i,'title_main'],}))
|
51 |
+
return placeholder
|
52 |
+
|
53 |
+
|
54 |
|
55 |
button=st.button("search")
|
56 |
|
57 |
+
chunks = get_chunks()
|
58 |
+
|
59 |
if button :
|
60 |
+
st.write(placeholder[0])
|