Chand11 commited on
Commit
2f9e1f6
·
verified ·
1 Parent(s): 21ad7f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -40
app.py CHANGED
@@ -1,46 +1,17 @@
1
- from fastapi import FastAPI
2
- from fastapi.middleware.cors import CORSMiddleware
3
  import gradio as gr
4
- import uvicorn
5
- from executor import recursive_executor
6
 
7
- # Create FastAPI app
8
- app = FastAPI(title="Recursive AI Executor")
9
 
10
- # Enable CORS
11
- app.add_middleware(
12
- CORSMiddleware,
13
- allow_origins=["*"],
14
- allow_credentials=True,
15
- allow_methods=["*"],
16
- allow_headers=["*"],
17
- )
18
 
19
- # Root endpoint
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
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
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()