Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,9 +34,6 @@ def get_data(url):
|
|
| 34 |
"List me all grants or funds, short summary of grant description, "
|
| 35 |
"the organisations funding them, the value of the grant as an integer, "
|
| 36 |
"the due date, eligible countries, sector and eligibility criteria for applicants."
|
| 37 |
-
|
| 38 |
-
"if you cant find grants return any useful information you can find"
|
| 39 |
-
|
| 40 |
),
|
| 41 |
source=url,
|
| 42 |
config=graph_config,
|
|
@@ -74,9 +71,6 @@ def process_multiple_urls(urls):
|
|
| 74 |
result = get_data(url)
|
| 75 |
if result and "grants" in result:
|
| 76 |
all_data["grants"].extend(result["grants"])
|
| 77 |
-
else:
|
| 78 |
-
all_data = result
|
| 79 |
-
|
| 80 |
except Exception as e:
|
| 81 |
st.error(f"⚠️ Error processing URL: {url} - {str(e)}")
|
| 82 |
continue
|
|
@@ -87,29 +81,16 @@ def process_multiple_urls(urls):
|
|
| 87 |
|
| 88 |
|
| 89 |
def convert_to_csv(data):
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
return df.to_csv(index=False).encode("utf-8")
|
| 93 |
-
except:
|
| 94 |
-
df = pd.DataFrame(data)
|
| 95 |
-
return df.to_csv(index=False).encode("utf-8")
|
| 96 |
|
| 97 |
|
| 98 |
def convert_to_excel(data):
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
return buffer.getvalue()
|
| 105 |
-
|
| 106 |
-
except:
|
| 107 |
-
df = pd.DataFrame(data)
|
| 108 |
-
buffer = io.BytesIO()
|
| 109 |
-
with pd.ExcelWriter(buffer, engine="xlsxwriter") as writer:
|
| 110 |
-
df.to_excel(writer, sheet_name="Grants", index=False)
|
| 111 |
-
return buffer.getvalue()
|
| 112 |
-
|
| 113 |
|
| 114 |
|
| 115 |
def create_knowledge_base(data):
|
|
@@ -203,10 +184,7 @@ def main():
|
|
| 203 |
|
| 204 |
# Data Preview and Download Options in Main Panel
|
| 205 |
with st.expander(f"📊 Preview Grant Data {len(st.session_state.scraped_data['grants'])} grants"):
|
| 206 |
-
|
| 207 |
-
st.dataframe(st.session_state.scraped_data["grants"])
|
| 208 |
-
except:
|
| 209 |
-
st.dataframe(st.session_state.scraped_data)
|
| 210 |
|
| 211 |
col1, col2, col3 = st.columns([1, 1, 2]) # Adjust column widths for better layout
|
| 212 |
|
|
@@ -252,12 +230,9 @@ def main():
|
|
| 252 |
|
| 253 |
query = st.text_input("Your question:", key="chat_input")
|
| 254 |
if query:
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
st.session_state.chat_history.append({"query": query, "response": response["answer"]})
|
| 259 |
-
else:
|
| 260 |
-
st.error("Knowledge base not initialized. Please load data as knowledge base.")
|
| 261 |
|
| 262 |
if st.session_state.chat_history:
|
| 263 |
st.subheader("Chat History")
|
|
@@ -279,6 +254,5 @@ def main():
|
|
| 279 |
unsafe_allow_html=True,
|
| 280 |
)
|
| 281 |
|
| 282 |
-
|
| 283 |
if __name__ == "__main__":
|
| 284 |
main()
|
|
|
|
| 34 |
"List me all grants or funds, short summary of grant description, "
|
| 35 |
"the organisations funding them, the value of the grant as an integer, "
|
| 36 |
"the due date, eligible countries, sector and eligibility criteria for applicants."
|
|
|
|
|
|
|
|
|
|
| 37 |
),
|
| 38 |
source=url,
|
| 39 |
config=graph_config,
|
|
|
|
| 71 |
result = get_data(url)
|
| 72 |
if result and "grants" in result:
|
| 73 |
all_data["grants"].extend(result["grants"])
|
|
|
|
|
|
|
|
|
|
| 74 |
except Exception as e:
|
| 75 |
st.error(f"⚠️ Error processing URL: {url} - {str(e)}")
|
| 76 |
continue
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
def convert_to_csv(data):
|
| 84 |
+
df = pd.DataFrame(data["grants"])
|
| 85 |
+
return df.to_csv(index=False).encode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
|
| 88 |
def convert_to_excel(data):
|
| 89 |
+
df = pd.DataFrame(data["grants"])
|
| 90 |
+
buffer = io.BytesIO()
|
| 91 |
+
with pd.ExcelWriter(buffer, engine="xlsxwriter") as writer:
|
| 92 |
+
df.to_excel(writer, sheet_name="Grants", index=False)
|
| 93 |
+
return buffer.getvalue()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
def create_knowledge_base(data):
|
|
|
|
| 184 |
|
| 185 |
# Data Preview and Download Options in Main Panel
|
| 186 |
with st.expander(f"📊 Preview Grant Data {len(st.session_state.scraped_data['grants'])} grants"):
|
| 187 |
+
st.dataframe(st.session_state.scraped_data["grants"])
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
col1, col2, col3 = st.columns([1, 1, 2]) # Adjust column widths for better layout
|
| 190 |
|
|
|
|
| 230 |
|
| 231 |
query = st.text_input("Your question:", key="chat_input")
|
| 232 |
if query:
|
| 233 |
+
with st.spinner("Generating response..."):
|
| 234 |
+
response = chat_with_knowledge_base(query)
|
| 235 |
+
st.session_state.chat_history.append({"query": query, "response": response["answer"]})
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
if st.session_state.chat_history:
|
| 238 |
st.subheader("Chat History")
|
|
|
|
| 254 |
unsafe_allow_html=True,
|
| 255 |
)
|
| 256 |
|
|
|
|
| 257 |
if __name__ == "__main__":
|
| 258 |
main()
|