Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
# বাংলা মন্তব্য সহ Hugging Face Space deploy-ready কোড
|
| 3 |
+
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import io
|
| 7 |
+
|
| 8 |
+
# -----------------------------
|
| 9 |
+
# Text → CSV Function
|
| 10 |
+
# -----------------------------
|
| 11 |
+
def text_to_csv(text_data):
|
| 12 |
+
try:
|
| 13 |
+
lines = text_data.strip().split("\n")
|
| 14 |
+
df = pd.DataFrame(lines, columns=["value"])
|
| 15 |
+
|
| 16 |
+
csv_buffer = io.StringIO()
|
| 17 |
+
df.to_csv(csv_buffer, index=False)
|
| 18 |
+
csv_content = csv_buffer.getvalue()
|
| 19 |
+
|
| 20 |
+
return df.head(), csv_content
|
| 21 |
+
except:
|
| 22 |
+
return None, "❌ Error converting text to CSV"
|
| 23 |
+
|
| 24 |
+
# -----------------------------
|
| 25 |
+
# Gradio UI
|
| 26 |
+
# -----------------------------
|
| 27 |
+
with gr.Blocks(theme=gr.themes.Monochrome()) as demo2:
|
| 28 |
+
gr.Markdown("## 📄 Text → CSV Converter\nবাংলায় সহজ UI, Dark Mode")
|
| 29 |
+
|
| 30 |
+
text_input = gr.Textbox(label="Paste Your Sequential Data", lines=10, placeholder="Example:\n1.23\n2.45\n1.10")
|
| 31 |
+
preview = gr.Dataframe(label="CSV Preview")
|
| 32 |
+
download = gr.File(label="Download CSV")
|
| 33 |
+
|
| 34 |
+
def process(text):
|
| 35 |
+
df, csv_content = text_to_csv(text)
|
| 36 |
+
if df is not None:
|
| 37 |
+
with open("output.csv", "w") as f:
|
| 38 |
+
f.write(csv_content)
|
| 39 |
+
return df, "output.csv"
|
| 40 |
+
else:
|
| 41 |
+
return None, None
|
| 42 |
+
|
| 43 |
+
text_input.change(fn=process, inputs=text_input, outputs=[preview, download])
|
| 44 |
+
|
| 45 |
+
demo2.launch()
|