Chang, Kai-Ching commited on
Commit
94d84df
·
1 Parent(s): 044cd00
Files changed (3) hide show
  1. README.md +2 -1
  2. app.py +53 -0
  3. requirements.txt +1 -0
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: SpaceB
3
- emoji: 📉
4
  colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
@@ -10,3 +10,4 @@ pinned: false
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
  title: SpaceB
3
+ emoji: 💻
4
  colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
13
+
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import csv
3
+ import os
4
+ from datetime import datetime
5
+
6
+ def generate_csv_from_text(user_text):
7
+ """
8
+ Takes text input and generates a CSV file
9
+ Input: String (user text)
10
+ Output: CSV file path
11
+ """
12
+ # Parse the text (split by commas or newlines)
13
+ lines = user_text.strip().split('\n')
14
+
15
+ # Generate filename with timestamp
16
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
17
+ csv_filename = f"output_{timestamp}.csv"
18
+
19
+ # Create CSV file
20
+ with open(csv_filename, 'w', newline='', encoding='utf-8') as csvfile:
21
+ writer = csv.writer(csvfile)
22
+
23
+ # Write header
24
+ writer.writerow(['Row_Number', 'Text_Content', 'Character_Count', 'Timestamp'])
25
+
26
+ # Write data rows
27
+ for idx, line in enumerate(lines, start=1):
28
+ writer.writerow([
29
+ idx,
30
+ line.strip(),
31
+ len(line.strip()),
32
+ datetime.now().strftime("%Y-%m-%d %H:%M:%S")
33
+ ])
34
+
35
+ print(f"✅ CSV generated: {csv_filename}")
36
+ return csv_filename
37
+
38
+ # Create Gradio Interface
39
+ demo = gr.Interface(
40
+ fn=generate_csv_from_text,
41
+ inputs=gr.Textbox(
42
+ label="Enter Text Data",
43
+ placeholder="Enter text (one item per line)\nExample:\nApple\nBanana\nCherry",
44
+ lines=5
45
+ ),
46
+ outputs=gr.File(label="Download CSV"),
47
+ title="Space B",
48
+ description="This is Space B: Takes text input and generates a CSV file.",
49
+ api_name="spaceB" # Important: Named API endpoint
50
+ )
51
+
52
+ if __name__ == "__main__":
53
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio