SanaomerUnity commited on
Commit
1fedbb8
·
verified ·
1 Parent(s): 855b245

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -1,20 +1,29 @@
1
  import gradio as gr
2
  import backgammon
3
 
4
-
5
  def greet(original_string):
6
- delimiter = "}}"
7
- split_parts = original_string.split(delimiter, 1)
8
- part1 = split_parts[0]
9
- part2 = delimiter + split_parts[1]
10
- part2 = part2.replace("}}", "")
11
- b = backgammon.Backgammon(part1, part2)
12
-
13
- for play in b.generate_plays():
14
- return play.moves
15
-
 
 
 
 
 
 
 
 
 
16
 
 
17
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")
18
  demo.queue(api_open=True)
19
 
20
- demo.launch()
 
1
  import gradio as gr
2
  import backgammon
3
 
 
4
  def greet(original_string):
5
+ delimiter = "}}"
6
+
7
+ # Split the string based on the delimiter
8
+ split_parts = original_string.split(delimiter, 1)
9
+
10
+ # Check if the delimiter is found and handle potential errors
11
+ if len(split_parts) < 2:
12
+ return "Input string is incorrectly formatted. Missing delimiter."
13
+
14
+ part1 = split_parts[0]
15
+ part2 = delimiter + split_parts[1]
16
+ part2 = part2.replace("}}", "")
17
+
18
+ # Ensure backgammon.Backgammon accepts these arguments
19
+ b = backgammon.Backgammon(part1, part2)
20
+
21
+ # Generate plays and return moves
22
+ for play in b.generate_plays():
23
+ return play.moves # Ensure play.moves is a string
24
 
25
+ # Ensure the inputs and outputs match what `greet` returns
26
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")
27
  demo.queue(api_open=True)
28
 
29
+ demo.launch()