R3BN commited on
Commit
fce7c51
·
verified ·
1 Parent(s): 8fea8d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -4
app.py CHANGED
@@ -1,7 +1,50 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"],
8
+ "adventure": ["The Legend of Zelda: Breath of the Wild", "Firewatch", "Life is Strange"],
9
+ "role-playing": ["The Witcher 3: Wild Hunt", "Final Fantasy VII", "Persona 5"],
10
+ "strategy": ["Civilization VI", "StarCraft II", "XCOM 2"],
11
+ "simulation": ["The Sims 4", "Stardew Valley", "Cities: Skylines"],
12
+ "sports": ["FIFA 21", "NBA 2K21", "Tony Hawk's Pro Skater 1+2"],
13
+ "puzzle": ["Portal 2", "The Witness", "Tetris Effect"],
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])
20
+ else:
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
+
49
+ if __name__ == "__main__":
50
+ launch_chatbot()