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