xiaonzxz's picture
update
672d147 verified
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()