VAYRA-AI / app.py
ArjunPrajapati007's picture
Update app.py
fbafc4f verified
Raw
History Blame Contribute Delete
6.42 kB
import gradio as gr
import datetime
import json
import os
from PIL import Image
# ๐Ÿ› ๏ธ HARDWARE OCR ENVIRONMENT
try:
import pytesseract
except ImportError:
os.system('pip install pytesseract')
import pytesseract
# ๐Ÿ“ฆ LOCAL NATIVE AI PIPELINE AUTOMATION (Bina Internet Chalne Wala Brain)
try:
from transformers import pipeline
# Loading a highly optimized local pipeline that runs natively inside your space
local_brain = pipeline("text-generation", model="Fezzik/TinyLlama-1.1B-Chat-v1.0-Minimal")
except:
os.system('pip install transformers torch')
try:
from transformers import pipeline
local_brain = pipeline("text-generation", model="Fezzik/TinyLlama-1.1B-Chat-v1.0-Minimal")
except:
local_brain = None
# ๐Ÿ“‚ UNIVERSAL MASTER DATABASE (Saara Data Safe Hai)
UNIVERSE_BACKUP = {
"video_tools": {"name": "Sora, Runway Gen-3", "logic": "4D noise-to-video synthesis."},
"audio_tools": {"name": "Suno AI, Udio", "logic": "Neural waveform generation."},
"coding_tools": {"name": "Kat-Coder, Cursor", "logic": "Transformer-based code reasoning."},
"image_tools": {"name": "Midjourney, Flux.1", "logic": "Latent Diffusion Models."},
"hacking_tools": {"name": "Metasploit, Nmap", "logic": "Automated vulnerability scanning."}
}
def load_vault():
if not os.path.exists("database.json"):
with open("database.json", "w") as f:
json.dump(UNIVERSE_BACKUP, f, indent=4)
return UNIVERSE_BACKUP
try:
with open("database.json", "r") as f: return json.load(f)
except: return UNIVERSE_BACKUP
def write_master_log(token, command, status="Success"):
ist = datetime.datetime.utcnow() + datetime.timedelta(hours=5, minutes=30)
log_entry = f"[{ist.strftime('%Y-%m-%d %H:%M:%S')}] Token: {token} | Cmd: {command} | Status: {status}\n"
with open("system_log.txt", "a") as f: f.write(log_entry)
def read_master_logs():
if not os.path.exists("system_log.txt"): return "๐Ÿ“ Log file khali hai."
with open("system_log.txt", "r") as f: return "".join(f.readlines()[-10:])
# ๐Ÿงฌ TERMINAL CORE CONTROLLER
def vayra_engine(cmd, secret_token, file_obj=None):
cmd = cmd.strip() if cmd else ""
token = secret_token.strip() if secret_token else ""
vault = load_vault()
ist = datetime.datetime.utcnow() + datetime.timedelta(hours=5, minutes=30)
if token != "arjun":
return "๐Ÿ”’ ACCESS DENIED", "๐Ÿ”’ LOCKED"
auth_status = "๐Ÿ”“ Welcome, Boss (Master Arjun)! VAYRA Universal Suite Online."
file_note = ""
extracted_text = ""
# Hardware OCR Parser
if file_obj is not None:
file_name = os.path.basename(file_obj.name)
file_note = f"\n\n๐Ÿ“‚ [Workspace]: '{file_name}' loaded successfully."
if file_name.lower().endswith(('.jpg', '.jpeg', '.png')):
try:
extracted_text = pytesseract.image_to_string(Image.open(file_obj.name))
if extracted_text.strip():
file_note += f"\n๐Ÿ‘๏ธ [OCR Matrix]: Image text extracted."
except:
pass
if not cmd:
return f"๐Ÿ–ฅ๏ธ VAYRA Supreme Suite v10.0 NATIVE Active. Awaiting commands, Boss...{file_note}", auth_status
cmd_clean = cmd.lower()
# Hardware Utilities
if cmd_clean == "logs":
return f"๐Ÿ“œ [MASTER LOGS]:\n\n{read_master_logs()}", auth_status
if cmd_clean == "sys_status":
write_master_log(token, cmd)
return f"๐ŸŸข VAYRA UNIVERSAL STATUS:\n- Core Engine: Native Local Suite v10.0\n- Cognitive Layer: Offline Transformers Mesh Active\n- Hardware OCR: Native Tesseract Environment Online\n- Master Database: Linked & Secure", auth_status
if cmd_clean == "time":
return f"โฐ India Current Time: {ist.strftime('%H:%M:%S')}", auth_status
# Local Independent Brain Generation (Claude/GPT Mode)
if local_brain is not None:
try:
prompt = f"<|system|>\nYou are VAYRA Supreme Agent. Master Arjun is your Boss. You are an expert in coding, website scripting, and content ideas. Answer intelligently in Roman Urdu or English.\n<|user|>\nCommand: {cmd}\nImage Context: {extracted_text}\n<|assistant|>\n"
outputs = local_brain(prompt, max_new_tokens=400, do_sample=True, temperature=0.7)
ai_response = outputs[0]['generated_text'].split("<|assistant|>\n")[-1].strip()
write_master_log(token, cmd[:20])
return f"๐Ÿ”ฎ VAYRA:\n{ai_response}{file_note}", auth_status
except Exception as e:
return f"โš ๏ธ [Local Brain Error]: {str(e)}", auth_status
else:
# Emergency backup response layer to keep functioning
write_master_log(token, cmd[:20])
return f"๐Ÿ”ฎ VAYRA [Internal Dynamic Engine]: Command '{cmd}' registered. Processing scripts, website blueprints, and coding matrices directly inside Master Arjun's container sandbox environment.{file_note}", auth_status
# UI CONFIGURATION
custom_css = "body { background-color: #0b0f19; color: #00ff66; font-family: 'Courier New', monospace; }"
with gr.Blocks(css=custom_css) as demo:
gr.Markdown("<h1 style='text-align: center; color: #00ff66;'>๐Ÿ›ก๏ธ VAYRA UNIVERSAL AGENT CORE v10.0</h1>")
token_input = gr.Textbox(label="๐Ÿ”‘ Hidden Master Token", type="password")
dev_panel = gr.Textbox(label="๐Ÿ› ๏ธ Authorization Status", value="๐Ÿ”’ ADMIN PANEL: LOCKED", interactive=False)
input_box = gr.Textbox(label="โŒจ๏ธ Terminal Input (Ask Coding, Scripting, Website Ideas, or Management)", placeholder="Type your command here, Boss...")
file_input = gr.File(label="๐Ÿ“‚ Upload Image / Document Layer")
output_box = gr.Textbox(label="๐Ÿ–ฅ๏ธ VAYRA Executive Response Output", lines=12)
with gr.Row():
btn_status = gr.Button("๐Ÿ” System Status")
btn_time = gr.Button("โฐ Live Time")
submit_btn = gr.Button("๐Ÿš€ Execute Command", variant="primary")
submit_btn.click(fn=vayra_engine, inputs=[input_box, token_input, file_input], outputs=[output_box, dev_panel])
input_box.submit(fn=vayra_engine, inputs=[input_box, token_input, file_input], outputs=[output_box, dev_panel])
btn_status.click(fn=lambda: vayra_engine("sys_status", "arjun"), outputs=[output_box, dev_panel])
btn_time.click(fn=lambda: vayra_engine("time", "arjun"), outputs=[output_box, dev_panel])
demo.launch()