Spaces:
No application file
No application file
Create research_app.py
Browse files- research_app.py +55 -0
research_app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
# Function to export data based on format choice
|
5 |
+
def export_data(data, format_choice):
|
6 |
+
if format_choice == 'CSV':
|
7 |
+
data.to_csv('exported_data.csv', index=False)
|
8 |
+
elif format_choice == 'JSON':
|
9 |
+
data.to_json('exported_data.json', orient='records')
|
10 |
+
elif format_choice == 'Excel':
|
11 |
+
data.to_excel('exported_data.xlsx', index=False)
|
12 |
+
else:
|
13 |
+
st.error("Unsupported format choice!")
|
14 |
+
|
15 |
+
# Streamlit app
|
16 |
+
def main():
|
17 |
+
st.title("Research Data Export")
|
18 |
+
|
19 |
+
# File upload section
|
20 |
+
st.header("Upload your data")
|
21 |
+
uploaded_file = st.file_uploader("Choose a file", type=["csv", "json", "xlsx"])
|
22 |
+
|
23 |
+
if uploaded_file is not None:
|
24 |
+
file_extension = uploaded_file.name.split(".")[-1]
|
25 |
+
|
26 |
+
try:
|
27 |
+
if file_extension == 'csv':
|
28 |
+
data = pd.read_csv(uploaded_file)
|
29 |
+
elif file_extension == 'json':
|
30 |
+
data = pd.read_json(uploaded_file)
|
31 |
+
elif file_extension in ['xlsx', 'xls']:
|
32 |
+
data = pd.read_excel(uploaded_file)
|
33 |
+
else:
|
34 |
+
st.error("Unsupported file format!")
|
35 |
+
return
|
36 |
+
|
37 |
+
st.success("Data loaded successfully!")
|
38 |
+
|
39 |
+
# Display loaded data
|
40 |
+
st.subheader("Loaded Data")
|
41 |
+
st.dataframe(data)
|
42 |
+
|
43 |
+
# Format export section
|
44 |
+
st.header("Export your data")
|
45 |
+
export_format = st.selectbox("Select export format", ["CSV", "JSON", "Excel"])
|
46 |
+
|
47 |
+
if st.button("Export"):
|
48 |
+
export_data(data, export_format)
|
49 |
+
st.success(f"Data exported successfully as {export_format}")
|
50 |
+
|
51 |
+
except Exception as e:
|
52 |
+
st.error(f"Error: {e}")
|
53 |
+
|
54 |
+
if __name__ == "__main__":
|
55 |
+
main()
|