Alejadro Sanchez-Giraldo commited on
Commit
58612e0
1 Parent(s): 86e230c

fixes to the team find theme

Browse files
Files changed (4) hide show
  1. .gitignore +3 -1
  2. app.py +18 -2
  3. nlp_utils.py +18 -5
  4. requirements.txt +2 -1
.gitignore CHANGED
@@ -2,4 +2,6 @@ fplenv/
2
  .DS_Store
3
  .env
4
 
5
- __pycache__/
 
 
 
2
  .DS_Store
3
  .env
4
 
5
+ __pycache__/
6
+
7
+ flagged
app.py CHANGED
@@ -2,6 +2,15 @@ import gradio as gr
2
  from fpl_client import FPLClient
3
  from nlp_utils import process_query
4
 
 
 
 
 
 
 
 
 
 
5
  # Initialize the FPL client
6
  fpl_client = FPLClient()
7
 
@@ -11,5 +20,12 @@ def chatbot_response(query):
11
  return response
12
 
13
  # Set up the Gradio interface
14
- iface = gr.Interface(fn=chatbot_response, inputs="text", outputs="text", title="FPL Chatbot")
15
- iface.launch()
 
 
 
 
 
 
 
 
2
  from fpl_client import FPLClient
3
  from nlp_utils import process_query
4
 
5
+ # Theme builder
6
+ # gr.themes.builder()
7
+
8
+ theme = gr.themes.Soft(
9
+ primary_hue="sky",
10
+ neutral_hue="slate",
11
+ )
12
+
13
+
14
  # Initialize the FPL client
15
  fpl_client = FPLClient()
16
 
 
20
  return response
21
 
22
  # Set up the Gradio interface
23
+ iface = gr.Interface(
24
+ fn=chatbot_response,
25
+ inputs=gr.Textbox(label="Ask our FPL Expert"),
26
+ outputs=gr.Textbox(label="Hope it helps!"),
27
+ theme=theme,
28
+ title="Devops1 FPL Chatbot"
29
+ )
30
+ if __name__ == "__main__":
31
+ iface.launch()
nlp_utils.py CHANGED
@@ -10,12 +10,14 @@ teams = fpl_client.get_teams()
10
 
11
  def extract_player_name(query):
12
  # Simple regex example to extract player names (can be enhanced)
13
- match = re.search(r"(\b[A-Z][a-z]+(?:\s[A-Z][a-z]+)?)", query)
 
 
14
  return match.group(1) if match else None
15
 
16
  def extract_team_name(query):
17
  logging.info(f"Extracting team name from query: {query}")
18
- logging.info(f"Teams: {teams}")
19
  # Add your logic to extract team names, could use a list of teams
20
  for team in teams:
21
  if team.lower() in query.lower():
@@ -30,11 +32,22 @@ def process_query(query, fpl_client):
30
  return stats
31
  return "Player name not found in the query."
32
 
33
- if "team" in query.lower():
 
34
  team_name = extract_team_name(query)
 
 
35
  if team_name:
 
36
  players = fpl_client.get_team_players(team_name)
37
- return f"Players from {team_name}: {', '.join(players)}"
38
- return "Team name not found in the query, please use from the list: " + ", ".join(teams)
 
 
 
 
 
 
39
 
 
40
  return "I'm not sure how to help with that."
 
10
 
11
  def extract_player_name(query):
12
  # Simple regex example to extract player names (can be enhanced)
13
+ # Updated regex to include accented characters and names with periods
14
+ match = re.search(r"(\b[A-Z][a-zA-Z]*[a-zA-Z.]*\b(?:\s[A-Z][a-zA-Z]*[a-zA-Z.]*\b)?)", query, re.UNICODE)
15
+ logging.info(f"Extracted player name: {match}")
16
  return match.group(1) if match else None
17
 
18
  def extract_team_name(query):
19
  logging.info(f"Extracting team name from query: {query}")
20
+ logging.debug(f"Teams: {teams}")
21
  # Add your logic to extract team names, could use a list of teams
22
  for team in teams:
23
  if team.lower() in query.lower():
 
32
  return stats
33
  return "Player name not found in the query."
34
 
35
+ if "team" in query.lower() or "players" in query.lower():
36
+ # Extract the team name from the query
37
  team_name = extract_team_name(query)
38
+
39
+ # Check if a valid team name was found
40
  if team_name:
41
+ # Get the list of players for the specified team
42
  players = fpl_client.get_team_players(team_name)
43
+
44
+ # Return the formatted list of players from the specified team
45
+ return f"Players from {team_name} are:\n" + "\n".join(players)
46
+
47
+ # If no valid team name was found, enumerate the teams and format them as a numbered list
48
+ enumerated_teams = [f"{index + 1}. {team}" for index, team in enumerate(teams)]
49
+
50
+ return "It sound like you need the latest EPL team list: " + "\n" + "\n".join(enumerated_teams)
51
 
52
+
53
  return "I'm not sure how to help with that."
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  huggingface_hub==0.22.2
2
  gradio
3
  requests
4
- transformers
 
 
1
  huggingface_hub==0.22.2
2
  gradio
3
  requests
4
+ transformers
5
+ minijinja