Allanatrix commited on
Commit
4dad6cd
·
verified ·
1 Parent(s): ef4c8c3

Delete Tokenization/app.py

Browse files
Files changed (1) hide show
  1. Tokenization/app.py +0 -147
Tokenization/app.py DELETED
@@ -1,147 +0,0 @@
1
- import gradio as gr
2
- import time
3
-
4
- def calculate_price(payment_mode, tokens, plan, custom_price, file):
5
- if payment_mode == "Pay as you go":
6
- price = round(tokens * 0.01, 2) # Example: $0.01 per token
7
- return f"{tokens:,} tokens\nPrice: ${price:.2f}", price
8
- elif payment_mode == "Plan":
9
- if plan == "Free":
10
- return "0 tokens\nPrice: $0", 0
11
- elif plan == "Starter":
12
- return "100,000 tokens\nPrice: $15", 15
13
- elif plan == "Pro":
14
- return "500,000 tokens\nPrice: $30", 30
15
- elif plan == "Custom":
16
- return f"Custom plan\nPrice: ${custom_price}", float(custom_price or 0)
17
- elif file is not None:
18
- # Simulate token count from file size
19
- tokens = 1000 # Replace it with real calculation
20
- price = round(tokens * 0.01, 2)
21
- return f"{tokens:,} tokens\nPrice: ${price:.2f}", price
22
- return "", 0
23
-
24
- def generate_dataset(*args, **kwargs):
25
- for i in range(5):
26
- yield f"Generating... ({(i+1)*20}%)", None, (i+1)/5
27
- time.sleep(0.3)
28
- yield "Ready! Please pay to download.", "dataset.jsonl", 1.0
29
-
30
- with gr.Blocks(
31
- title="Nexa Data Studio",
32
- css="""
33
- body, .gradio-container {
34
- min-height: 100vh;
35
- background: #111 !important;
36
- color: #fff !important;
37
- }
38
- .gradio-container {
39
- max-width: 900px !important;
40
- margin: 40px auto !important;
41
- box-shadow: 0 2px 16px #0008;
42
- border-radius: 16px;
43
- padding: 32px 32px 24px 32px !important;
44
- background: #111 !important;
45
- color: #fff !important;
46
- display: flex;
47
- flex-direction: column;
48
- align-items: center;
49
- }
50
- .footer {margin-top: 2em; color: #bbb; font-size: 0.9em; text-align: center;}
51
- #header {text-align: center;}
52
- """
53
- ) as demo:
54
- gr.Markdown(
55
- """
56
- <div style="display:flex;align-items:center;gap:16px;justify-content:center;">
57
- <img src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg" height="40"/>
58
- <h1 style="margin-bottom:0;">Nexa Data Studio</h1>
59
- </div>
60
- <p style="text-align:center;">
61
- <b>Generate or label scientific datasets for ML research.</b>
62
- </p>
63
- """,
64
- elem_id="header"
65
- )
66
-
67
- payment_mode = gr.Radio(
68
- ["Pay as you go", "Plan"],
69
- label="Payment Mode",
70
- value="Pay as you go"
71
- )
72
-
73
- with gr.Row() as payg_row:
74
- tokens = gr.Slider(100, 100000, value=1000, step=100, label="Tokens Requested")
75
- with gr.Row(visible=False) as plan_row:
76
- plan = gr.Dropdown(
77
- ["Free", "Starter", "Pro", "Custom"],
78
- label="Plan",
79
- value="Free"
80
- )
81
- custom_price = gr.Number(label="Custom Price ($)", visible=False)
82
-
83
- job_type = gr.Radio(
84
- ["Generate Dataset", "Label Uploaded Data"],
85
- label="Job Type",
86
- value="Generate Dataset"
87
- )
88
-
89
- with gr.Column(visible=False) as label_col:
90
- file = gr.File(label="Upload Dataset (.txt or .jsonl)")
91
-
92
- price_info = gr.Textbox(label="Summary", interactive=False)
93
- download = gr.File(label="Download")
94
- progress = gr.Slider(0, 1, value=0, step=0.01, label="Progress", interactive=False)
95
- status = gr.Text(label="Status", interactive=False)
96
-
97
- def update_payment_ui(payment_mode_val, plan_val):
98
- return (
99
- gr.update(visible=payment_mode_val == "Pay as you go"),
100
- gr.update(visible=payment_mode_val == "Plan"),
101
- gr.update(visible=payment_mode_val == "Plan" and plan_val == "Custom")
102
- )
103
-
104
- payment_mode.change(
105
- update_payment_ui,
106
- inputs=[payment_mode, plan],
107
- outputs=[payg_row, plan_row, custom_price]
108
- )
109
- plan.change(
110
- lambda p: gr.update(visible=p == "Custom"),
111
- inputs=plan,
112
- outputs=custom_price
113
- )
114
-
115
- def update_label_ui(job_type_val):
116
- return gr.update(visible=job_type_val == "Label Uploaded Data")
117
- job_type.change(update_label_ui, inputs=job_type, outputs=label_col)
118
-
119
- def update_summary(payment_mode, tokens, plan, custom_price, file, job_type):
120
- if job_type == "Label Uploaded Data" and file is not None:
121
- return calculate_price("Label", tokens, plan, custom_price, file)[0]
122
- return calculate_price(payment_mode, tokens, plan, custom_price, file)[0]
123
-
124
- inputs = [payment_mode, tokens, plan, custom_price, file, job_type]
125
- gr.Button("Generate", elem_id="generate-btn", variant="primary").click(
126
- generate_dataset,
127
- inputs=inputs,
128
- outputs=[status, download, progress]
129
- )
130
- gr.Button("Update Summary").click(
131
- update_summary,
132
- inputs=inputs,
133
- outputs=price_info
134
- )
135
-
136
- gr.Markdown(
137
- f"""
138
- <div class="footer">
139
- &copy; {time.strftime("%Y")} Nexa Data Studio &mdash; Powered by Hugging Face Spaces<br>
140
- For support, contact <a href="mailto:[email protected]">[email protected]</a>
141
- </div>
142
- """
143
- )
144
-
145
- if __name__ == "__main__":
146
- demo.launch(server_name="0.0.0.0", server_port=7860, show_error=True)
147
- print("Nexa Data Studio is running at http://localhost:7860")