Spaces:
Sleeping
Sleeping
File size: 2,128 Bytes
8fea8d3 fce7c51 2cfcf79 fce7c51 2cfcf79 fce7c51 2cfcf79 fce7c51 8fea8d3 fce7c51 2cfcf79 fce7c51 2cfcf79 fce7c51 2cfcf79 fce7c51 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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()
|