Download app.py from lilbotai/pricing_: direct link, hf CLI and curl.
- Browser
- Download file 2.28 kB
-
https://huggingface.co/spaces/lilbotai/pricing_/resolve/main/app.py
- Command line
-
hf download hf://spaces/lilbotai/pricing_/app.py
-
curl -L -o app.py https://huggingface.co/spaces/lilbotai/pricing_/resolve/main/app.py
2.28 kB
| import gradio as gr | |
| import tempfile | |
| import os | |
| def calculate_cost(dataset_size, epoch_size, model_name): | |
| # Calculate costs | |
| file_cost = dataset_size * 0.05 | |
| epoch_cost = epoch_size * 0.01 | |
| total_cost = file_cost + epoch_cost | |
| # Create receipt text | |
| receipt = ( | |
| f"Price Calculator Receipt\n" | |
| f"-------------------------\n" | |
| f"Model Name: {model_name}\n" | |
| f"Dataset Size: {dataset_size} audio files\n" | |
| f"Epoch Size: {epoch_size} epochs\n" | |
| f"Cost for Dataset: ${file_cost:.2f}\n" | |
| f"Cost for Epochs: ${epoch_cost:.2f}\n" | |
| f"Total Cost: ${total_cost:.2f}\n" | |
| ) | |
| # Save the receipt as a temporary file with the model name as the file name | |
| temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".txt", prefix=f"{model_name}_") | |
| with open(temp_file.name, "w") as file: | |
| file.write(receipt) | |
| return receipt, temp_file.name | |
| # Gradio app interface | |
| with gr.Blocks() as app: | |
| gr.Markdown("### Voiceclone X Price Calculator") | |
| with gr.Row(): | |
| model_name = gr.Textbox( | |
| label="Model Name", | |
| placeholder="Enter Model Name", | |
| lines=1 | |
| ) | |
| with gr.Row(): | |
| dataset_size = gr.Radio( | |
| label="Select Dataset Size (number of audio files)", | |
| choices=[25, 50, 75, 100, 150, 200, 250, 300], | |
| value=150 | |
| ) | |
| with gr.Row(): | |
| epoch_size = gr.Radio( | |
| label="Select Epoch Size (number of epochs)", | |
| choices=[250, 500, 1000, 1500, 2000, 2500, 3000], | |
| value=2500 | |
| ) | |
| result = gr.Textbox( | |
| label="Results", | |
| lines=10, | |
| interactive=False, | |
| placeholder="Calculation results will appear here." | |
| ) | |
| # Change: Use gr.File for direct file download | |
| download_button = gr.File(label="Download Receipt") | |
| calculate_button = gr.Button("Calculate Cost") | |
| def wrapper(dataset_size, epoch_size, model_name): | |
| receipt, temp_file = calculate_cost(dataset_size, epoch_size, model_name) | |
| return receipt, temp_file | |
| calculate_button.click( | |
| fn=wrapper, | |
| inputs=[dataset_size, epoch_size, model_name], | |
| outputs=[result, download_button] | |
| ) | |
| # Launch the app | |
| app.launch() | |