doxiy commited on
Commit
b67e2e5
·
1 Parent(s): 88e53f9

version complète v1

Browse files
Files changed (5) hide show
  1. .env +2 -0
  2. .gitignore +1 -0
  3. agent.py +52 -0
  4. app.py +10 -48
  5. gaia_submit.py +51 -0
.env ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ OPENAI_API_KEY=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
2
+ SERPER_API_KEY=b97ff40a98e2f23d5eaf2215898a16e414b044a3
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ Pipfile*
agent.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from llama_index.llms.openai import OpenAI
3
+ from llama_index.agent.openai import OpenAIAgent
4
+ from tools import TOOLS
5
+
6
+ import os
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+
11
+ # 🔑 Variables d'environnement
12
+ openai_api_key = os.getenv("OPENAI_API_KEY")
13
+ os.environ["OPENAI_API_KEY"] = openai_api_key
14
+
15
+
16
+
17
+ # 🧠 Création de l'agent
18
+ llm = OpenAI(
19
+ model="gpt-3.5-turbo",
20
+ system_prompt=(
21
+ "Tu es un agent expert GAIA. "
22
+ "Tu dois réfléchir étape par étape et utiliser les outils disponibles si besoin. "
23
+ "Privilégie les réponses factuelles, sourcées et structurées."
24
+ ),
25
+ max_tokens=500
26
+ )
27
+
28
+ agent = OpenAIAgent.from_tools(
29
+ tools=TOOLS,
30
+ llm=llm,
31
+ verbose=True
32
+ )
33
+
34
+ # 🚀 Point d'entrée principal
35
+ def run_agent(question: str) -> str:
36
+ """Interface principale pour l'agent"""
37
+ try:
38
+ response = agent.chat(question)
39
+ return str(response)
40
+ except Exception as e:
41
+ return f"Erreur: {str(e)}"
42
+
43
+ if __name__ == "__main__":
44
+ # Interface Gradio
45
+ demo = gr.Interface(
46
+ fn=run_agent,
47
+ inputs=gr.Textbox(label="Votre question", placeholder="Posez votre question..."),
48
+ outputs=gr.Textbox(label="Réponse de l'agent"),
49
+ title="🤖 Agent GAIA avec DuckDuckGo",
50
+ description="Agent intelligent avec recherche web intégrée"
51
+ )
52
+ demo.launch()
app.py CHANGED
@@ -1,52 +1,14 @@
1
  import gradio as gr
2
- from llama_index.llms.openai import OpenAI
3
- from llama_index.agent.openai import OpenAIAgent
4
- from tools import TOOLS
5
-
6
- import os
7
- from dotenv import load_dotenv
8
-
9
- load_dotenv()
10
-
11
- # 🔑 Variables d'environnement
12
- openai_api_key = os.getenv("OPENAI_API_KEY")
13
- os.environ["OPENAI_API_KEY"] = openai_api_key
14
-
15
-
16
-
17
- # 🧠 Création de l'agent
18
- llm = OpenAI(
19
- model="gpt-3.5-turbo",
20
- system_prompt=(
21
- "Tu es un agent expert GAIA. "
22
- "Tu dois réfléchir étape par étape et utiliser les outils disponibles si besoin. "
23
- "Privilégie les réponses factuelles, sourcées et structurées."
24
- ),
25
- max_tokens=500
26
- )
27
-
28
- agent = OpenAIAgent.from_tools(
29
- tools=TOOLS,
30
- llm=llm,
31
- verbose=True
32
  )
33
 
34
- # 🚀 Point d'entrée principal
35
- def run_agent(question: str) -> str:
36
- """Interface principale pour l'agent"""
37
- try:
38
- response = agent.chat(question)
39
- return str(response)
40
- except Exception as e:
41
- return f"Erreur: {str(e)}"
42
 
43
- if __name__ == "__main__":
44
- # Interface Gradio
45
- demo = gr.Interface(
46
- fn=run_agent,
47
- inputs=gr.Textbox(label="Votre question", placeholder="Posez votre question..."),
48
- outputs=gr.Textbox(label="Réponse de l'agent"),
49
- title="🤖 Agent GAIA avec DuckDuckGo",
50
- description="Agent intelligent avec recherche web intégrée"
51
- )
52
- demo.launch()
 
1
  import gradio as gr
2
+ from gaia_submit import run_agent_on_all_questions # ← importe ta fonction
3
+
4
+ # UI de Gradio
5
+ demo = gr.Interface(
6
+ fn=run_agent_on_all_questions,
7
+ inputs=[],
8
+ outputs="textbox",
9
+ title="GAIA Final Agent",
10
+ description="Cet agent répond aux questions GAIA et envoie au leaderboard."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  )
12
 
13
+ demo.launch()
 
 
 
 
 
 
 
14
 
 
 
 
 
 
 
 
 
 
 
gaia_submit.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from pydantic import BaseModel
3
+ from agent import run_agent
4
+
5
+
6
+ #structure attendu
7
+ class Question(BaseModel):
8
+ task_id: str
9
+ question: str
10
+ file_name: str = None
11
+
12
+ class Answer(BaseModel):
13
+ task_id: str
14
+ submitted_answer: str
15
+
16
+ def answer_question(question:str) -> str:
17
+ return str(run_agent(question)).strip()
18
+
19
+
20
+ def run_agent_on_all_questions():
21
+ #1. Obtenir les question
22
+ response = requests.get("https://gaia-course-api.spaces.huggingface.tech/questions")
23
+ questions = response.json()
24
+
25
+ answers = []
26
+ logs=""
27
+
28
+ for i, q in enumerate(questions):
29
+ try:
30
+ reponse = answer_question(q['question'])
31
+ answers.append({"task_id" : q["task_id"], "submitted_answer" : reponse})
32
+ logs += f"{i+1}. {q['question']} → {reponse}\n"
33
+ except Exception as e:
34
+ logs += f"Error en {q['task_id']}: {str(e)}\n"
35
+
36
+
37
+ #2. envoi de la reponse
38
+ payload = {
39
+ "username": "Doxiy",
40
+ "agent_code": "https://huggingface.co/spaces/doxiy/exam-agent/tree/main",
41
+ "answers": answers
42
+ }
43
+
44
+
45
+ r = requests.post("https://gaia-course-api.spaces.huggingface.tech/submit", json=payload)
46
+ if r.status_code == 200:
47
+ logs += "\n✅ Envoi avec succes. Resultat:\n" + str(r.json())
48
+ else:
49
+ logs += f"\n❌ Error envoie. Code {r.status_code} - {r.text}"
50
+
51
+ return logs