Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,21 +1,29 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
|
| 5 |
def query_zeroclaw(user_input):
|
| 6 |
-
api_key = os.getenv("
|
| 7 |
if not api_key:
|
| 8 |
-
return "Error:
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
demo = gr.Interface(
|
| 14 |
fn=query_zeroclaw,
|
| 15 |
-
inputs=gr.Textbox(label="Enter your query
|
| 16 |
-
outputs=gr.Textbox(label="
|
| 17 |
-
title="ZeroClaw on Hugging Face Spaces",
|
| 18 |
-
description="
|
| 19 |
)
|
| 20 |
|
| 21 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
import openai
|
| 4 |
|
| 5 |
def query_zeroclaw(user_input):
|
| 6 |
+
api_key = os.getenv("OPENROUTER_API_KEY")
|
| 7 |
if not api_key:
|
| 8 |
+
return "Error: OPENROUTER_API_KEY not set in Spaces secrets. Get one at https://openrouter.ai/keys"
|
| 9 |
+
|
| 10 |
+
client = openai.OpenAI(
|
| 11 |
+
base_url="https://openrouter.ai/api/v1",
|
| 12 |
+
api_key=api_key,
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
response = client.chat.completions.create(
|
| 16 |
+
model="anthropic/claude-3.5-sonnet:beta",
|
| 17 |
+
messages=[{"role": "user", "content": user_input}]
|
| 18 |
+
)
|
| 19 |
+
return response.choices[0].message.content
|
| 20 |
|
| 21 |
demo = gr.Interface(
|
| 22 |
fn=query_zeroclaw,
|
| 23 |
+
inputs=gr.Textbox(label="Enter your query", lines=3),
|
| 24 |
+
outputs=gr.Textbox(label="AI Response", lines=10),
|
| 25 |
+
title="ZeroClaw-style AI Agent on Hugging Face Spaces",
|
| 26 |
+
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."
|
| 27 |
)
|
| 28 |
|
| 29 |
if __name__ == "__main__":
|