Spaces:
Running
Running
Create index.html
Browse files- index.html +61 -0
index.html
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@gradio/lite@5/dist/lite.js"></script>
|
| 5 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite@5/dist/lite.css" />
|
| 6 |
+
</head>
|
| 7 |
+
<body>
|
| 8 |
+
<gradio-app requirements="openai">
|
| 9 |
+
import gradio as gr
|
| 10 |
+
from openai import OpenAI
|
| 11 |
+
|
| 12 |
+
def run_descriptor_agent(openai_key, user_prompt):
|
| 13 |
+
if not openai_key:
|
| 14 |
+
return "Please enter your OpenAI API Key first!"
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
# Initialize the OpenAI client inside the browser-lite environment
|
| 18 |
+
client = OpenAI(api_key=openai_key)
|
| 19 |
+
|
| 20 |
+
# Simple agent/LLM descriptor call
|
| 21 |
+
response = client.chat.completions.create(
|
| 22 |
+
model="gpt-4o-mini",
|
| 23 |
+
messages=[
|
| 24 |
+
{"role": "system", "content": "You are a professional AI Descriptor agent. Provide structured, clear summaries and descriptions based on user requests."},
|
| 25 |
+
{"role": "user", "content": user_prompt}
|
| 26 |
+
]
|
| 27 |
+
)
|
| 28 |
+
return response.choices[0].message.content
|
| 29 |
+
except Exception as e:
|
| 30 |
+
return f"Error: {str(e)}"
|
| 31 |
+
|
| 32 |
+
# Define a clean Gradio Blocks Interface
|
| 33 |
+
with gr.Blocks() as demo:
|
| 34 |
+
gr.Markdown("# AI Descriptor Agent")
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
key_input = gr.Textbox(
|
| 38 |
+
label="1. Enter your OpenAI API Key",
|
| 39 |
+
placeholder="sk-proj-...",
|
| 40 |
+
type="password"
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
with gr.Row():
|
| 44 |
+
prompt_input = gr.Textbox(
|
| 45 |
+
label="2. Ask the Agent anything",
|
| 46 |
+
placeholder="Describe what you want me to analyze..."
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
submit_btn = gr.Button("Run Agent", variant="primary")
|
| 50 |
+
output_text = gr.Textbox(label="Agent Response", interactive=False)
|
| 51 |
+
|
| 52 |
+
submit_btn.click(
|
| 53 |
+
fn=run_descriptor_agent,
|
| 54 |
+
inputs=[key_input, prompt_input],
|
| 55 |
+
outputs=output_text
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
demo.launch()
|
| 59 |
+
</gradio-app>
|
| 60 |
+
</body>
|
| 61 |
+
</html>
|