Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,17 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
-
import uvicorn
|
| 5 |
-
from executor import recursive_executor
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
allow_methods=["*"],
|
| 16 |
-
allow_headers=["*"],
|
| 17 |
-
)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
@app.get("/")
|
| 21 |
-
def root():
|
| 22 |
-
return {"message": "🚀 Recursive AI Executor is running on Hugging Face!"}
|
| 23 |
|
| 24 |
-
# Run recursive executor for Gradio
|
| 25 |
-
def run_executor(task: str):
|
| 26 |
-
try:
|
| 27 |
-
result = recursive_executor(task)
|
| 28 |
-
return result
|
| 29 |
-
except Exception as e:
|
| 30 |
-
return f"❌ Error: {e}"
|
| 31 |
-
|
| 32 |
-
# Build Gradio UI
|
| 33 |
-
demo = gr.Interface(
|
| 34 |
-
fn=run_executor,
|
| 35 |
-
inputs=gr.Textbox(label="Enter your task", placeholder="e.g. Write Python code for Fibonacci"),
|
| 36 |
-
outputs=gr.Textbox(label="Result"),
|
| 37 |
-
title="Recursive AI Executor",
|
| 38 |
-
description="Enter a task and let the AI recursively break it down and solve it."
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
-
# Mount Gradio app inside FastAPI
|
| 42 |
-
app = gr.mount_gradio_app(app, demo, path="/app")
|
| 43 |
-
|
| 44 |
-
# Run server
|
| 45 |
if __name__ == "__main__":
|
| 46 |
-
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
# Get Gemini API key from Hugging Face Secrets
|
| 6 |
+
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
| 7 |
|
| 8 |
+
# Simple test function
|
| 9 |
+
def ask_gemini(prompt):
|
| 10 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 11 |
+
response = model.generate_content(prompt)
|
| 12 |
+
return response.text
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
demo = gr.Interface(fn=ask_gemini, inputs="text", outputs="text")
|
|
|
|
|
|
|
|
|
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
if __name__ == "__main__":
|
| 17 |
+
demo.launch()
|