File size: 1,431 Bytes
4e2df85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os
import requests

# Google AI Studio / Gemini Connections
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")

def opencode_agent_engine(user_prompt):
    if not GEMINI_API_KEY:
        return "Error: Gemini API Key is missing! Please add it in Space Settings."
    
    # OpenCode Core Logic combined with Gemini Brain
    payload = {
        "contents": [{"parts": [{"text": f"Act as OpenCode AI Agent. Task: {user_prompt}"}]}]
    }
    url = f"https://googleapis.com{GEMINI_API_KEY}"
    
    try:
        response = requests.post(url, json=payload)
        result = response.json()
        return result['candidates'][0]['content']['parts'][0]['text']
    except Exception as e:
        return f"OpenCode Connection Error: {str(e)}"

# Premium Dark Theme UI for your Factory
with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("# 🚀 OpenCode AI Cloud Agent Factory")
    gr.Markdown("Your limitless automated software factory running 24/7 on cloud.")
    
    with gr.Row():
        input_box = gr.Textbox(label="Instruct OpenCode (e.g., Build a responsive website)", placeholder="Type your software requirements here...")
    
    submit_btn = gr.Button("Execute OpenCode Engine", variant="primary")
    output_box = gr.Code(label="Generated Software Code / Output", language="html")
    
    submit_btn.click(fn=opencode_agent_engine, inputs=input_box, outputs=output_box)

demo.launch()