munio commited on
Commit
54212a7
·
1 Parent(s): 3972146

added app.py

Browse files
Files changed (2) hide show
  1. app.py +31 -0
  2. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ def romanToInt(s):
3
+ """
4
+ :type s: str
5
+ :rtype: int
6
+ """
7
+ num = {
8
+ 'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000
9
+ }
10
+ value = 0
11
+ i = 0
12
+ while i < len(s)-1:
13
+
14
+ if num[s[i]] < num[s[i+1]]:
15
+ value += num[s[i+1]] - num[s[i]]
16
+ i += 2
17
+ else:
18
+ value += num[s[i]]
19
+ i += 1
20
+ if i == len(s)-1:
21
+ value += num[s[i]]
22
+ return value
23
+
24
+ interface = gr.Interface(
25
+ fn=romanToInt,
26
+ inputs=gr.Textbox(label="Roman Number"),
27
+ outputs=gr.Number(label="Integer"),
28
+ title="Roman to Integer",
29
+ description="Please enter Roman numerals (I, V, X, L, C, D, M) in uppercase."
30
+ )
31
+ interface.launch()
requirements.txt ADDED
File without changes