File size: 2,177 Bytes
2cdc05c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import requests
from dotenv import load_dotenv
from flask import Flask, request
from flask_sqlalchemy import SQLAlchemy
from gradio import Button, Interface, Textbox

# Initialize Flask app
app = Flask(__name__)

# Load environment variables
load_dotenv()

# Initialize SQLAlchemy
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///game.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)

# Define your SQLAlchemy model
class Character(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100))
    level = db.Column(db.Integer)
    class_ = db.Column(db.String(50))
    health = db.Column(db.Integer)
    strength = db.Column(db.Integer)
    agility = db.Column(db.Integer)

# Define your Flask routes
@app.route('/')
def index():
    return "Welcome to the RPG Game!"

@app.route('/create_character', methods=['POST'])
def create_character():
    # Parse input data from request
    data = request.json
    name = data['name']
    level = data['level']
    class_ = data['class']
    health = data['health']
    strength = data['strength']
    agility = data['agility']
    # Create a new character instance
    character = Character(name=name, level=level, class_=class_, health=health, strength=strength, agility=agility)
    db.session.add(character)
    db.session.commit()
    return f"Character {name} created successfully!"

# Define Gradio interface components
textbox = Textbox(placeholder="Character name")
button = Button("Create Character")

# Define function to be called when button is clicked
def create_character_callback(name):
    # Send request to Flask route to create character
    response = requests.post("http://localhost:5000/create_character", json={"name": name, "level": 1, "class": "Warrior", "health": 100, "strength": 10, "agility": 5})
    return f"Character {name} created successfully!"

# Create Gradio interface
iface = Interface(inputs=textbox, outputs=create_character_callback, title="RPG Character Creator", theme="compact", layout="vertical", server_name="localhost", server_port=8080)

if __name__ == '__main__':
    # Run Flask app
    app.run(port=5000, debug=True)