Futuretech.ai / app.py
Itachi674's picture
Update app.py
8525bc3 verified
Raw
History Blame Contribute Delete
3.29 kB
import gradio as gr
import requests
import time
import traceback
TEXT_MODEL = "https://api-inference.huggingface.co/models/Qwen/Qwen2.5-Coder-1.5B-Instruct"
IMAGE_MODEL = "https://api-inference.huggingface.co/models/stabilityai/sdxl-turbo"
# ---------- TEXT MODEL ----------
def call_model(prompt, tokens=160):
payload = {
"inputs": prompt,
"parameters": {
"max_new_tokens": tokens,
"temperature": 0.6
}
}
for _ in range(5):
r = requests.post(TEXT_MODEL, json=payload)
if r.status_code == 200:
return r.json()[0]["generated_text"]
time.sleep(2)
return "โš  Model busy. Try again."
# ---------- GAME MODULES ----------
def generate_player(game_desc):
return call_model(f"Create only the PlayerController script for: {game_desc}. No explanation.")
def generate_obstacles(game_desc):
return call_model(f"Create only the obstacle spawning script for: {game_desc}. No explanation.")
def generate_scoring(game_desc):
return call_model(f"Create only the scoring system script for: {game_desc}. No explanation.")
def generate_manager(game_desc):
return call_model(f"Create only the GameManager script for: {game_desc}. No explanation.")
# ---------- IMAGE GENERATOR ----------
def generate_image(prompt):
r = requests.post(IMAGE_MODEL, json={"inputs": prompt})
if r.status_code == 200:
return r.content
return None
# ---------- SECURE CODE RUNNER ----------
def run_code(code):
try:
allowed_builtins = {
"print": print,
"range": range,
"len": len,
"int": int,
"float": float,
"str": str
}
exec(code, {"__builtins__": allowed_builtins}, {})
return "โœ… Code executed safely."
except Exception:
return traceback.format_exc()
# ---------- UI ----------
with gr.Blocks(theme=gr.themes.Soft()) as app:
gr.Markdown("# ๐Ÿš€ FutureTech AI Lab")
gr.Markdown("Modular โ€ข Free โ€ข Stable")
with gr.Tabs():
# Game Builder
with gr.Tab("๐ŸŽฎ Game Builder"):
game_input = gr.Textbox(label="Describe your game")
output = gr.Textbox(lines=18)
with gr.Row():
btn1 = gr.Button("Player")
btn2 = gr.Button("Obstacles")
btn3 = gr.Button("Scoring")
btn4 = gr.Button("Manager")
btn1.click(generate_player, game_input, output)
btn2.click(generate_obstacles, game_input, output)
btn3.click(generate_scoring, game_input, output)
btn4.click(generate_manager, game_input, output)
# Image Generator
with gr.Tab("๐ŸŽจ Image Generator"):
img_prompt = gr.Textbox(label="Describe image")
img_btn = gr.Button("Generate Image")
img_output = gr.Image()
img_btn.click(generate_image, img_prompt, img_output)
# Code Runner
with gr.Tab("๐Ÿงช Code Runner"):
code_input = gr.Textbox(lines=12, label="Python Code (Safe Mode)")
code_btn = gr.Button("Run Code")
code_output = gr.Textbox(lines=5)
code_btn.click(run_code, code_input, code_output)
app.launch()