File size: 1,416 Bytes
7437a2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
# app.py
# বাংলা মন্তব্য সহ Hugging Face Space deploy-ready কোড

import gradio as gr
import pandas as pd
import io

# -----------------------------
# Text → CSV Function
# -----------------------------
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"

# -----------------------------
# Gradio UI
# -----------------------------
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()