Spaces:
Sleeping
Sleeping
import os | |
import gradio as gr | |
from time import sleep | |
def indian_notation(num): | |
num_str = str(num) | |
if '.' in num_str: | |
num_str = '{:.2f}'.format(float(num_str)).rstrip('0').rstrip('.') | |
integer_part, decimal_part = num_str.split(".") | |
decimal_part = "." + decimal_part | |
else: | |
integer_part, decimal_part = num_str, "" | |
rev = integer_part[::-1] | |
if len(rev) < 4: | |
return rev[::-1] + decimal_part | |
three_part, rest = rev[:3], rev[3:] | |
rest = ",".join([rest[i:i+2] for i in range(0, len(rest), 2)]) | |
return (rest[::-1] + "," + three_part[::-1]) + decimal_part | |
def compute_roi(avg_duration, estd_courses, course_price, price_dubbing, course_name): | |
sleep(1) | |
estd_courses = float(estd_courses) | |
avg_duration = float(avg_duration) | |
course_price = float(course_price) | |
price_dubbing = float(price_dubbing) | |
new_markdown = f"""## ROI for Course: <ins>{course_name}</ins> | |
## _For a batch of **{int(estd_courses)}** students, for average **{avg_duration:g} hours** of duration, you are expected to earn ₹{indian_notation(int(estd_courses * course_price))}._ | |
## _The estimated cost for dubbing this course is ₹{indian_notation(int(price_dubbing*60*avg_duration))} paid in monthly installments._ | |
## _Your ROI is approximately {int((estd_courses * course_price) / (price_dubbing*60*avg_duration) * 100)}%._ | |
""" | |
return gr.update(value=new_markdown, visible=True) | |
def calcualte_cost_capacity(content_hours, pricing_per_minute, expected_delivery_days, avg_translator_speed, translators_pay_per_month): | |
sleep(1) | |
total_revenue = float(content_hours) * float(pricing_per_minute) * 60 | |
expected_num_people = int(float(content_hours) * 60 / (float(avg_translator_speed) * float(expected_delivery_days))) | |
company_cost_beared = expected_num_people * float(expected_delivery_days) * float(translators_pay_per_month) / 30 | |
res_markdown = f"""## Cost Capacity | |
## _Total Revenue Generated : ₹{indian_notation(int(total_revenue))}_ | |
## _Expected Number of Translators required : {expected_num_people}_ | |
## _Cost beared for Translators : ₹{indian_notation(int(company_cost_beared))}_ | |
## _Total Earnings : ₹{indian_notation(int(total_revenue-company_cost_beared))}_ | |
""" | |
return gr.update(value=res_markdown, visible=True) | |
with gr.Blocks(theme="gradio/monochrome") as demo: | |
gr.Markdown("# Dubbing Course ROI Calculator") | |
with gr.Row(): | |
course_name_txt = gr.Textbox(label="Course Name") | |
category = gr.Dropdown(["CA", "Finance", "JEE", "CMA", "NEET", "Biology", "Chemistry", "Physics", "Others"], label="Course Category") | |
with gr.Row(): | |
avg_duration_num = gr.Number(label="Average Duration (hours)") | |
num_courses = gr.Number(label="Number of Courses") | |
course_price_txt = gr.Textbox(label="Estimated Course Price") | |
with gr.Row(): | |
source_lang = gr.Dropdown(["English", "Hindi", "Tamil"], label="Source Language") | |
target_lang = gr.Dropdown(["English", "Hindi", "Tamil"], label="Target Language") | |
with gr.Row(): | |
estd_courses_num = gr.Number(label="Estimated Dubbed Courses Sold", info="Assuming one person buys one course.") | |
price_dubbing_txt = gr.Textbox(label="Dubpro's Per Minute Price", info="This price is inclusive of GST.") | |
calc_roi = gr.Button("Calculate ROI") | |
output = gr.Markdown() | |
calc_roi.click(compute_roi, [avg_duration_num, estd_courses_num, course_price_txt, price_dubbing_txt, course_name_txt], output) | |
gr.Markdown("# Course Cost Capacity") | |
with gr.Row(): | |
content_hours_num = gr.Number(label="Hours of Content") | |
pricing_per_minute_num = gr.Number(label="Price of Course Per Minute of Dubbing (in Rs)") | |
expected_delivery_days_num = gr.Number(label="Expected Number of Days for Delivery") | |
with gr.Row(): | |
avg_translator_speed_num = gr.Number(label="Speed of Average Translator Per Day (in minutes)") | |
translators_pay_per_month_num = gr.Number(label="Average Cost of Translator per Month (in Rs)") | |
calcualte_cost_capacity_btn = gr.Button("Calculate Cost Capacity") | |
output_2 = gr.Markdown() | |
calcualte_cost_capacity_btn.click(calcualte_cost_capacity, [content_hours_num, pricing_per_minute_num, expected_delivery_days_num, avg_translator_speed_num, translators_pay_per_month_num], output_2) | |
demo.launch() |