File size: 1,050 Bytes
a174695
 
0f11385
a174695
 
0f11385
a174695
0f11385
 
 
 
 
 
 
 
 
 
 
 
a174695
 
 
0f11385
 
 
 
a174695
 
 
 
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
import os
import gradio as gr
import openai

def query_zeroclaw(user_input):
    api_key = os.getenv("OPENROUTER_API_KEY")
    if not api_key:
        return "Error: OPENROUTER_API_KEY not set in Spaces secrets. Get one at https://openrouter.ai/keys"
    
    client = openai.OpenAI(
        base_url="https://openrouter.ai/api/v1",
        api_key=api_key,
    )
    
    response = client.chat.completions.create(
        model="anthropic/claude-3.5-sonnet:beta",
        messages=[{"role": "user", "content": user_input}]
    )
    return response.choices[0].message.content

demo = gr.Interface(
    fn=query_zeroclaw,
    inputs=gr.Textbox(label="Enter your query", lines=3),
    outputs=gr.Textbox(label="AI Response", lines=10),
    title="ZeroClaw-style AI Agent on Hugging Face Spaces",
    description="AI agent powered by OpenRouter. Get your free API key at https://openrouter.ai/keys and add it to Spaces secrets as OPENROUTER_API_KEY."
)

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860, share=False)