import gradio as gr from groq import Groq import sqlite3 # Initialize the database def init_db(): conn = sqlite3.connect('games.db') cursor = conn.cursor() cursor.execute(''' CREATE TABLE IF NOT EXISTS games ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, description TEXT, status TEXT ) ''') cursor.execute(''' CREATE TABLE IF NOT EXISTS players ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, game_id INTEGER, hp INTEGER, xp INTEGER, FOREIGN KEY (game_id) REFERENCES games (id) ) ''') conn.commit() conn.close() # Function to interact with the chatbot using Gemma model def chatbot_interface(input_text): # Initialize Gemma model client = Groq() system_message = { "role": "system", "content": "You are a game management assistant. You can add, list, and update games, manage players, and handle player actions. Use commands like 'add game GameName Description', 'list games', 'update game GameID Status', 'add player PlayerName GameID', 'list players GameID', 'player action PlayerID Action'." } user_message = { "role": "user", "content": input_text } # Call the Gemma model for chat completion chat_completion = client.chat.completions.create( messages=[system_message, user_message], model="gemma-7b-it", temperature=0.5, max_tokens=100, top_p=1, stream=False ) response = chat_completion.choices[0].message.content.strip() return response # Initialize the database init_db() # Create Gradio interface iface = gr.Interface(fn=chatbot_interface, inputs="textbox", outputs="text", title="Multiplayer RPG Arcade Chatbot", description="Create and manage RPG games, add players, and perform actions using commands. Example commands: 'add game GameName Description', 'list games', 'update game GameID Status', 'add player PlayerName GameID', 'list players GameID', 'player action PlayerID Action'.") # Launch the interface iface.launch(share=True)