rairo commited on
Commit
f4a4691
·
verified ·
1 Parent(s): 2946558

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -36
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
- st.title("Quantilytix Grant Scraper")
62
-
63
- url = st.text_input("Enter URL")
64
-
65
- if "scraped_data" not in st.session_state:
66
- st.session_state.scraped_data = None
67
-
68
- if st.button("Get grants"):
69
- if url:
70
- try:
71
- with st.spinner("Retrieving Grants, Please Wait...."):
72
- result = get_data(url)
73
- st.session_state.scraped_data = result # Store result in session state
74
- st.success("Data scraped successfully!")
75
- except Exception as e:
76
- st.error(f"Error scraping data: {e}")
77
- else:
78
- st.warning("Please enter a URL.")
79
-
80
- if st.session_state.scraped_data:
81
- selected_format = st.selectbox("Select Download Format", ("CSV", "Excel"))
82
-
83
- result = st.session_state.scraped_data # Access the saved result
84
-
85
- if selected_format == "CSV":
86
- csv_data = convert_to_csv(result)
87
- b64 = base64.b64encode(csv_data).decode()
88
- download_link = f"<a href='data:application/vnd.ms-excel;base64,{b64}' download='grants.csv'>Download CSV</a>"
89
- st.markdown(download_link, unsafe_allow_html=True)
90
- elif selected_format == "Excel":
91
- excel_data = convert_to_excel(result)
92
- b64 = base64.b64encode(excel_data).decode()
93
- download_link = f"<a href='data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{b64}' download='grants.xlsx'>Download Excel</a>"
94
- st.markdown(download_link, unsafe_allow_html=True)
95
-
96
- st.dataframe(result['grants'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()