R3BN commited on
Commit
2cfcf79
·
verified ·
1 Parent(s): fce7c51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
 
3
  # Define the game recommendations based on genre
4
- def recommend_games(genre, chat_history):
5
  # Game recommendations dictionary
6
  game_recommendations = {
7
  "action": ["God of War", "Dark Souls", "Spider-Man"],
@@ -14,6 +14,9 @@ def recommend_games(genre, chat_history):
14
  "horror": ["Resident Evil 7", "Amnesia: The Dark Descent", "Outlast"],
15
  }
16
 
 
 
 
17
  # Prepare the response
18
  if genre in game_recommendations:
19
  response = f"Here are some {genre} games you might enjoy:\n" + "\n".join(game_recommendations[genre])
@@ -21,28 +24,21 @@ def recommend_games(genre, chat_history):
21
  response = "I'm sorry, I don't have recommendations for that genre. Please try one of the following genres:\n" + ", ".join(game_recommendations.keys())
22
 
23
  # Update chat history
24
- chat_history.append((genre, response))
25
  return "", chat_history # Clear the input and return updated chat history
26
 
27
  # Create and launch the Gradio interface
28
  def launch_chatbot():
29
  with gr.Blocks() as iface:
30
  gr.Markdown("## Game Recommendation Chatbot")
31
- gr.Markdown("Tell me your preferred genre by clicking one of the buttons below:")
 
32
 
33
  chat_history = gr.Chatbot(label="Chat History")
34
-
35
- # Create genre buttons
36
- genres = ["action", "adventure", "role-playing", "strategy", "simulation", "sports", "puzzle", "horror"]
37
- genre_buttons = [gr.Button(genre.capitalize()) for genre in genres]
38
 
39
- # Define button click actions
40
- for button in genre_buttons:
41
- button.click(recommend_games, inputs=[button.value, chat_history], outputs=[None, chat_history])
42
-
43
- # Add a placeholder for chat history
44
- gr.Markdown("### Chat History")
45
- chat_history = gr.Chatbot(label="Chat History")
46
 
47
  iface.launch()
48
 
 
1
  import gradio as gr
2
 
3
  # Define the game recommendations based on genre
4
+ def recommend_games(user_input, chat_history):
5
  # Game recommendations dictionary
6
  game_recommendations = {
7
  "action": ["God of War", "Dark Souls", "Spider-Man"],
 
14
  "horror": ["Resident Evil 7", "Amnesia: The Dark Descent", "Outlast"],
15
  }
16
 
17
+ # Normalize the input genre to lowercase
18
+ genre = user_input.lower()
19
+
20
  # Prepare the response
21
  if genre in game_recommendations:
22
  response = f"Here are some {genre} games you might enjoy:\n" + "\n".join(game_recommendations[genre])
 
24
  response = "I'm sorry, I don't have recommendations for that genre. Please try one of the following genres:\n" + ", ".join(game_recommendations.keys())
25
 
26
  # Update chat history
27
+ chat_history.append((user_input, response))
28
  return "", chat_history # Clear the input and return updated chat history
29
 
30
  # Create and launch the Gradio interface
31
  def launch_chatbot():
32
  with gr.Blocks() as iface:
33
  gr.Markdown("## Game Recommendation Chatbot")
34
+ gr.Markdown("Tell me your preferred genre from the following options:")
35
+ gr.Markdown("**Available Genres:** action, adventure, role-playing, strategy, simulation, sports, puzzle, horror")
36
 
37
  chat_history = gr.Chatbot(label="Chat History")
38
+ user_input = gr.Textbox(label="Your Preferred Genre", placeholder="Type your genre here...")
39
+ submit_btn = gr.Button("Submit")
 
 
40
 
41
+ submit_btn.click(recommend_games, inputs=[user_input, chat_history], outputs=[user_input, chat_history])
 
 
 
 
 
 
42
 
43
  iface.launch()
44