Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # Define the game recommendations based on genre | |
| def recommend_games(user_input, chat_history): | |
| # Game recommendations dictionary | |
| game_recommendations = { | |
| "action": ["God of War", "Dark Souls", "Spider-Man"], | |
| "adventure": ["The Legend of Zelda: Breath of the Wild", "Firewatch", "Life is Strange"], | |
| "role-playing": ["The Witcher 3: Wild Hunt", "Final Fantasy VII", "Persona 5"], | |
| "strategy": ["Civilization VI", "StarCraft II", "XCOM 2"], | |
| "simulation": ["The Sims 4", "Stardew Valley", "Cities: Skylines"], | |
| "sports": ["FIFA 21", "NBA 2K21", "Tony Hawk's Pro Skater 1+2"], | |
| "puzzle": ["Portal 2", "The Witness", "Tetris Effect"], | |
| "horror": ["Resident Evil 7", "Amnesia: The Dark Descent", "Outlast"], | |
| } | |
| # Normalize the input genre to lowercase | |
| genre = user_input.lower() | |
| # Prepare the response | |
| if genre in game_recommendations: | |
| response = f"Here are some {genre} games you might enjoy:\n" + "\n".join(game_recommendations[genre]) | |
| else: | |
| response = "I'm sorry, I don't have recommendations for that genre. Please try one of the following genres:\n" + ", ".join(game_recommendations.keys()) | |
| # Update chat history | |
| chat_history.append((user_input, response)) | |
| return "", chat_history # Clear the input and return updated chat history | |
| # Create and launch the Gradio interface | |
| def launch_chatbot(): | |
| with gr.Blocks() as iface: | |
| gr.Markdown("## Game Recommendation Chatbot") | |
| gr.Markdown("Tell me your preferred genre from the following options:") | |
| gr.Markdown("**Available Genres:** action, adventure, role-playing, strategy, simulation, sports, puzzle, horror") | |
| chat_history = gr.Chatbot(label="Chat History") | |
| user_input = gr.Textbox(label="Your Preferred Genre", placeholder="Type your genre here...") | |
| submit_btn = gr.Button("Submit") | |
| submit_btn.click(recommend_games, inputs=[user_input, chat_history], outputs=[user_input, chat_history]) | |
| iface.launch() | |
| if __name__ == "__main__": | |
| launch_chatbot() | |