File size: 2,711 Bytes
6f1b639
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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)

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)

demo.launch(auth=(os.environ.get("USERNAME"), os.environ.get("PASSWORD")))