| |
| |
|
|
| import gradio as gr |
| import pandas as pd |
| import io |
|
|
| |
| |
| |
| def text_to_csv(text_data): |
| try: |
| lines = text_data.strip().split("\n") |
| df = pd.DataFrame(lines, columns=["value"]) |
| |
| csv_buffer = io.StringIO() |
| df.to_csv(csv_buffer, index=False) |
| csv_content = csv_buffer.getvalue() |
| |
| return df.head(), csv_content |
| except: |
| return None, "❌ Error converting text to CSV" |
|
|
| |
| |
| |
| with gr.Blocks(theme=gr.themes.Monochrome()) as demo2: |
| gr.Markdown("## 📄 Text → CSV Converter\nবাংলায় সহজ UI, Dark Mode") |
|
|
| text_input = gr.Textbox(label="Paste Your Sequential Data", lines=10, placeholder="Example:\n1.23\n2.45\n1.10") |
| preview = gr.Dataframe(label="CSV Preview") |
| download = gr.File(label="Download CSV") |
|
|
| def process(text): |
| df, csv_content = text_to_csv(text) |
| if df is not None: |
| with open("output.csv", "w") as f: |
| f.write(csv_content) |
| return df, "output.csv" |
| else: |
| return None, None |
|
|
| text_input.change(fn=process, inputs=text_input, outputs=[preview, download]) |
|
|
| demo2.launch() |
|
|