Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
|
| 4 |
+
def run_agent(openai_key, user_prompt):
|
| 5 |
+
if not openai_key:
|
| 6 |
+
return "Please enter your OpenAI API Key first!"
|
| 7 |
+
|
| 8 |
+
try:
|
| 9 |
+
# Initialize the OpenAI client right inside the function
|
| 10 |
+
client = OpenAI(api_key=openai_key)
|
| 11 |
+
|
| 12 |
+
# Simple agent/LLM call (adjust the prompt/system message to match your specific agent logic)
|
| 13 |
+
response = client.chat.completions.create(
|
| 14 |
+
model="gpt-4o-mini", # Highly capable and fast default
|
| 15 |
+
messages=[
|
| 16 |
+
{"role": "system", "content": "You are a helpful AI Descriptor agent."},
|
| 17 |
+
{"role": "user", "content": user_prompt}
|
| 18 |
+
]
|
| 19 |
+
)
|
| 20 |
+
return response.choices[0].message.content
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return f"Error: {str(e)}"
|
| 23 |
+
|
| 24 |
+
# Define a clean Gradio Interface
|
| 25 |
+
with gr.Blocks() as demo:
|
| 26 |
+
gr.Markdown("# AI Descriptor Agent")
|
| 27 |
+
|
| 28 |
+
with gr.Row():
|
| 29 |
+
key_input = gr.Textbox(
|
| 30 |
+
label="1. Enter your OpenAI API Key",
|
| 31 |
+
placeholder="sk-proj-...",
|
| 32 |
+
type="password"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
with gr.Row():
|
| 36 |
+
prompt_input = gr.Textbox(
|
| 37 |
+
label="2. Ask the Agent anything",
|
| 38 |
+
placeholder="Describe what you need..."
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
submit_btn = gr.Button("Run Agent")
|
| 42 |
+
output_text = gr.Textbox(label="Agent Response")
|
| 43 |
+
|
| 44 |
+
submit_btn.click(
|
| 45 |
+
fn=run_agent,
|
| 46 |
+
inputs=[key_input, prompt_input],
|
| 47 |
+
outputs=output_text
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
demo.launch()
|