Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
|
@@ -1,4 +1,44 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from io import StringIO
|
| 4 |
|
| 5 |
+
def main():
|
| 6 |
+
st.title("CSV Upload or Text Input App")
|
| 7 |
|
| 8 |
+
# App description
|
| 9 |
+
st.write("""
|
| 10 |
+
This app allows you to:
|
| 11 |
+
1. Upload a CSV file to process the data.
|
| 12 |
+
2. Enter multiple rows of text directly into a text area.
|
| 13 |
+
""")
|
| 14 |
+
|
| 15 |
+
# File uploader
|
| 16 |
+
uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
|
| 17 |
+
|
| 18 |
+
# Text input section
|
| 19 |
+
st.write("OR")
|
| 20 |
+
st.write("Enter your text rows below (one row per line):")
|
| 21 |
+
user_text_input = st.text_area("Text Input", height=150, placeholder="Type or paste your rows of text here...")
|
| 22 |
+
|
| 23 |
+
# Process CSV upload
|
| 24 |
+
if uploaded_file:
|
| 25 |
+
try:
|
| 26 |
+
# Read the uploaded CSV
|
| 27 |
+
df = pd.read_csv(uploaded_file)
|
| 28 |
+
st.write("### Uploaded CSV File:")
|
| 29 |
+
st.dataframe(df)
|
| 30 |
+
except Exception as e:
|
| 31 |
+
st.error(f"Error reading file: {e}")
|
| 32 |
+
|
| 33 |
+
# Process manual text input
|
| 34 |
+
elif user_text_input.strip():
|
| 35 |
+
# Split text into rows and create a DataFrame
|
| 36 |
+
text_rows = user_text_input.strip().split("\n")
|
| 37 |
+
text_df = pd.DataFrame({"text": text_rows})
|
| 38 |
+
st.write("### Entered Text Data:")
|
| 39 |
+
st.dataframe(text_df)
|
| 40 |
+
else:
|
| 41 |
+
st.write("Upload a CSV file or enter text to see the data.")
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
main()
|