File size: 721 Bytes
54212a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
def romanToInt(s):
    """
    :type s: str
    :rtype: int
    """
    num = {
        'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000
    }
    value = 0
    i = 0
    while i < len(s)-1:
        
        if num[s[i]] < num[s[i+1]]:
            value += num[s[i+1]] - num[s[i]]
            i += 2
        else:
            value += num[s[i]]
            i += 1
    if i == len(s)-1:
        value += num[s[i]]
    return value

interface = gr.Interface(
    fn=romanToInt,
    inputs=gr.Textbox(label="Roman Number"),
    outputs=gr.Number(label="Integer"),
    title="Roman to Integer",
    description="Please enter Roman numerals (I, V, X, L, C, D, M) in uppercase."
)
interface.launch()