sithumonline commited on
Commit
bd1188e
·
1 Parent(s): c1db03c

Call AI via API

Browse files
Files changed (2) hide show
  1. app.py +38 -0
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import gradio as gr
2
  from typing import List
 
 
3
 
4
  DESCRIPTION = '''
5
  <div>
@@ -34,6 +36,18 @@ boardTemplate = """
34
  </center>
35
  """
36
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  css = """
38
  table {
39
  border-collapse: collapse;
@@ -61,6 +75,29 @@ winConditions = [
61
  squares: List[str] = [" " for i in range(9)]
62
 
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  def botPlayer(squares: List[str]) -> int:
65
  print("Bot's turn")
66
  if squares[4] == " ":
@@ -124,6 +161,7 @@ def on_submit(number):
124
  return boardTemplate.format(*squares)
125
 
126
  bot_move = botPlayer(squares)
 
127
  if is_empty(squares, bot_move):
128
  squares[bot_move] = " O "
129
  if checkWin(False, squares):
 
1
  import gradio as gr
2
  from typing import List
3
+ from gradio_client import Client
4
+
5
 
6
  DESCRIPTION = '''
7
  <div>
 
36
  </center>
37
  """
38
 
39
+ aiBoardTemplate = """"
40
+ 0 1 2
41
+ +-----+-----+-----+
42
+ | {0} | {1} | {2} |
43
+ +-----+-----+-----+
44
+ 3 | {3} | {4} | {5} | 5
45
+ +-----+-----+-----+
46
+ | {6} | {7} | {8} |
47
+ +-----+-----+-----+
48
+ 6 7 8
49
+ """
50
+
51
  css = """
52
  table {
53
  border-collapse: collapse;
 
75
  squares: List[str] = [" " for i in range(9)]
76
 
77
 
78
+ def aiPlayer(squares: List[str]) -> int:
79
+ print("AI's turn")
80
+ prompt = f""""
81
+ The board is:
82
+
83
+ {aiBoardTemplate.format(*squares)}
84
+
85
+ It's your turn. Enter the number of the square you want to place your 'O' in.
86
+ Only enter the number of the square. For example, if you want to place your 'O' in the top right square, enter '2'.
87
+ """
88
+
89
+ client = Client("ysharma/Chat_with_Meta_llama3_8b")
90
+ result = client.predict(
91
+ message=prompt,
92
+ request=0.95,
93
+ param_3=512,
94
+ api_name="/chat"
95
+ )
96
+ print(result)
97
+
98
+ return 0
99
+
100
+
101
  def botPlayer(squares: List[str]) -> int:
102
  print("Bot's turn")
103
  if squares[4] == " ":
 
161
  return boardTemplate.format(*squares)
162
 
163
  bot_move = botPlayer(squares)
164
+ aiPlayer(squares)
165
  if is_empty(squares, bot_move):
166
  squares[bot_move] = " O "
167
  if checkWin(False, squares):
requirements.txt CHANGED
@@ -1 +1,2 @@
1
  gradio==4.26.0
 
 
1
  gradio==4.26.0
2
+ gradio-client==0.16.0