Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -58,39 +58,55 @@ def convert_to_excel(data):
|
|
| 58 |
df.to_excel(writer, sheet_name='Grants', index=False)
|
| 59 |
return buffer.getvalue()
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
st.
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
df.to_excel(writer, sheet_name='Grants', index=False)
|
| 59 |
return buffer.getvalue()
|
| 60 |
|
| 61 |
+
|
| 62 |
+
def main():
|
| 63 |
+
st.sidebar.title("Quantilytix Grant Scraper")
|
| 64 |
+
|
| 65 |
+
url = st.sidebar.text_input("Enter URL")
|
| 66 |
+
|
| 67 |
+
if "scraped_data" not in st.session_state:
|
| 68 |
+
st.session_state.scraped_data = None
|
| 69 |
+
|
| 70 |
+
if st.sidebar.button("Get grants"):
|
| 71 |
+
if url:
|
| 72 |
+
try:
|
| 73 |
+
with st.spinner("Retrieving Grants, Please Wait...."):
|
| 74 |
+
result = get_data(url)
|
| 75 |
+
st.session_state.scraped_data = result # Store result in session state
|
| 76 |
+
st.success("Data scraped successfully!")
|
| 77 |
+
except Exception as e:
|
| 78 |
+
st.error(f"Error scraping data: {e}")
|
| 79 |
+
else:
|
| 80 |
+
st.warning("Please enter a URL.")
|
| 81 |
+
|
| 82 |
+
if st.session_state.scraped_data:
|
| 83 |
+
selected_format = st.sidebar.selectbox("Select Download Format", ("CSV", "Excel"))
|
| 84 |
+
|
| 85 |
+
result = st.session_state.scraped_data # Access the saved result
|
| 86 |
+
|
| 87 |
+
if selected_format == "CSV":
|
| 88 |
+
csv_data = convert_to_csv(result)
|
| 89 |
+
b64 = base64.b64encode(csv_data).decode()
|
| 90 |
+
download_link = f"<a href='data:application/vnd.ms-excel;base64,{b64}' download='grants.csv'>Download CSV</a>"
|
| 91 |
+
st.sidebar.markdown(download_link, unsafe_allow_html=True)
|
| 92 |
+
elif selected_format == "Excel":
|
| 93 |
+
excel_data = convert_to_excel(result)
|
| 94 |
+
b64 = base64.b64encode(excel_data).decode()
|
| 95 |
+
download_link = f"<a href='data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{b64}' download='grants.xlsx'>Download Excel</a>"
|
| 96 |
+
st.sidebar.markdown(download_link, unsafe_allow_html=True)
|
| 97 |
+
|
| 98 |
+
st.dataframe(result['grants'])
|
| 99 |
+
|
| 100 |
+
if st.sidebar.button("Load as Knowledge Base"):
|
| 101 |
+
if st.session_state.scraped_data is not None:
|
| 102 |
+
st.write("Chat Interface Loaded. Start asking questions about the grants!")
|
| 103 |
+
query = st.text_input("Ask a question about the grants:", key="chat_input")
|
| 104 |
+
if query:
|
| 105 |
+
response = "This is where the response based on the knowledge base would be generated." # Placeholder
|
| 106 |
+
st.write("Response:")
|
| 107 |
+
st.write(response)
|
| 108 |
+
else:
|
| 109 |
+
st.warning("No data available. Please scrape grants first.")
|
| 110 |
+
|
| 111 |
+
if __name__ == "__main__":
|
| 112 |
+
main()
|