Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -3,7 +3,7 @@ import gradio as gr 
     | 
|
| 3 | 
         
             
            from crew import run_crew
         
     | 
| 4 | 
         
             
            from utils import get_questions
         
     | 
| 5 | 
         | 
| 6 | 
         
            -
            def _run(question, openai_api_key, gemini_api_key, file_name = ""):
         
     | 
| 7 | 
         
             
                """
         
     | 
| 8 | 
         
             
                Run GAIA General AI Assistant to answer a question.
         
     | 
| 9 | 
         | 
| 
         @@ -11,6 +11,7 @@ def _run(question, openai_api_key, gemini_api_key, file_name = ""): 
     | 
|
| 11 | 
         
             
                    question (str): The question to answer
         
     | 
| 12 | 
         
             
                    openai_api_key (str): OpenAI API key
         
     | 
| 13 | 
         
             
                    gemini_api_key (str): Gemini API key
         
     | 
| 
         | 
|
| 14 | 
         
             
                    file_name (str): Optional file name
         
     | 
| 15 | 
         | 
| 16 | 
         
             
                Returns:
         
     | 
| 
         @@ -25,6 +26,9 @@ def _run(question, openai_api_key, gemini_api_key, file_name = ""): 
     | 
|
| 25 | 
         
             
                if not gemini_api_key:
         
     | 
| 26 | 
         
             
                    raise gr.Error("Gemini API Key is required.")
         
     | 
| 27 | 
         | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 28 | 
         
             
                if file_name:
         
     | 
| 29 | 
         
             
                    file_name = f"data/{file_name}"
         
     | 
| 30 | 
         | 
| 
         @@ -36,6 +40,7 @@ def _run(question, openai_api_key, gemini_api_key, file_name = ""): 
     | 
|
| 36 | 
         
             
                    try:
         
     | 
| 37 | 
         
             
                        os.environ["OPENAI_API_KEY"] = openai_api_key
         
     | 
| 38 | 
         
             
                        os.environ["GEMINI_API_KEY"] = gemini_api_key
         
     | 
| 
         | 
|
| 39 | 
         | 
| 40 | 
         
             
                        answer = run_crew(question, file_name)
         
     | 
| 41 | 
         
             
                    except Exception as e:
         
     | 
| 
         @@ -43,6 +48,7 @@ def _run(question, openai_api_key, gemini_api_key, file_name = ""): 
     | 
|
| 43 | 
         
             
                    finally:
         
     | 
| 44 | 
         
             
                        del os.environ["OPENAI_API_KEY"]
         
     | 
| 45 | 
         
             
                        del os.environ["GEMINI_API_KEY"]
         
     | 
| 
         | 
|
| 46 | 
         | 
| 47 | 
         
             
                    return answer
         
     | 
| 48 | 
         | 
| 
         @@ -81,9 +87,13 @@ with gr.Blocks() as gaia: 
     | 
|
| 81 | 
         
             
                                label="Gemini API Key *",
         
     | 
| 82 | 
         
             
                                type="password"
         
     | 
| 83 | 
         
             
                            )
         
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 84 | 
         
             
                        with gr.Row():
         
     | 
| 85 | 
         
             
                            clear_btn = gr.ClearButton(
         
     | 
| 86 | 
         
            -
                                components=[question, level, ground_truth, file_name 
     | 
| 87 | 
         
             
                            )
         
     | 
| 88 | 
         
             
                            submit_btn = gr.Button("Submit", variant="primary")
         
     | 
| 89 | 
         
             
                    with gr.Column(scale=1):
         
     | 
| 
         @@ -95,7 +105,7 @@ with gr.Blocks() as gaia: 
     | 
|
| 95 | 
         | 
| 96 | 
         
             
                submit_btn.click(
         
     | 
| 97 | 
         
             
                    fn=_run,
         
     | 
| 98 | 
         
            -
                    inputs=[question, openai_api_key, gemini_api_key, file_name],
         
     | 
| 99 | 
         
             
                    outputs=answer
         
     | 
| 100 | 
         
             
                )
         
     | 
| 101 | 
         | 
| 
         @@ -104,7 +114,7 @@ with gr.Blocks() as gaia: 
     | 
|
| 104 | 
         
             
                gr.Examples(
         
     | 
| 105 | 
         
             
                    label="Level 1",
         
     | 
| 106 | 
         
             
                    examples=get_questions(QUESTION_FILE_PATH, 1),
         
     | 
| 107 | 
         
            -
                    inputs=[question, level, ground_truth, file_name, openai_api_key, gemini_api_key],
         
     | 
| 108 | 
         
             
                    outputs=answer,
         
     | 
| 109 | 
         
             
                    cache_examples=False
         
     | 
| 110 | 
         
             
                )
         
     | 
| 
         @@ -112,7 +122,7 @@ with gr.Blocks() as gaia: 
     | 
|
| 112 | 
         
             
                gr.Examples(
         
     | 
| 113 | 
         
             
                    label="Level 2",
         
     | 
| 114 | 
         
             
                    examples=get_questions(QUESTION_FILE_PATH, 2),
         
     | 
| 115 | 
         
            -
                    inputs=[question, level, ground_truth, file_name, openai_api_key, gemini_api_key],
         
     | 
| 116 | 
         
             
                    outputs=answer,
         
     | 
| 117 | 
         
             
                    cache_examples=False
         
     | 
| 118 | 
         
             
                )
         
     | 
| 
         @@ -120,7 +130,7 @@ with gr.Blocks() as gaia: 
     | 
|
| 120 | 
         
             
                gr.Examples(
         
     | 
| 121 | 
         
             
                    label="Level 3",
         
     | 
| 122 | 
         
             
                    examples=get_questions(QUESTION_FILE_PATH, 3),
         
     | 
| 123 | 
         
            -
                    inputs=[question, level, ground_truth, file_name, openai_api_key, gemini_api_key],
         
     | 
| 124 | 
         
             
                    outputs=answer,
         
     | 
| 125 | 
         
             
                    cache_examples=False
         
     | 
| 126 | 
         
             
                )
         
     | 
| 
         | 
|
| 3 | 
         
             
            from crew import run_crew
         
     | 
| 4 | 
         
             
            from utils import get_questions
         
     | 
| 5 | 
         | 
| 6 | 
         
            +
            def _run(question, openai_api_key, gemini_api_key, anthropic_api_key, file_name = ""):
         
     | 
| 7 | 
         
             
                """
         
     | 
| 8 | 
         
             
                Run GAIA General AI Assistant to answer a question.
         
     | 
| 9 | 
         | 
| 
         | 
|
| 11 | 
         
             
                    question (str): The question to answer
         
     | 
| 12 | 
         
             
                    openai_api_key (str): OpenAI API key
         
     | 
| 13 | 
         
             
                    gemini_api_key (str): Gemini API key
         
     | 
| 14 | 
         
            +
                    anthropic_api_key (str): Anthropic API key
         
     | 
| 15 | 
         
             
                    file_name (str): Optional file name
         
     | 
| 16 | 
         | 
| 17 | 
         
             
                Returns:
         
     | 
| 
         | 
|
| 26 | 
         
             
                if not gemini_api_key:
         
     | 
| 27 | 
         
             
                    raise gr.Error("Gemini API Key is required.")
         
     | 
| 28 | 
         | 
| 29 | 
         
            +
                if not anthropic_api_key:
         
     | 
| 30 | 
         
            +
                    raise gr.Error("Anthropic API Key is required.")
         
     | 
| 31 | 
         
            +
                    
         
     | 
| 32 | 
         
             
                if file_name:
         
     | 
| 33 | 
         
             
                    file_name = f"data/{file_name}"
         
     | 
| 34 | 
         | 
| 
         | 
|
| 40 | 
         
             
                    try:
         
     | 
| 41 | 
         
             
                        os.environ["OPENAI_API_KEY"] = openai_api_key
         
     | 
| 42 | 
         
             
                        os.environ["GEMINI_API_KEY"] = gemini_api_key
         
     | 
| 43 | 
         
            +
                        os.environ["ANTHROPIC_API_KEY"] = anthropic_api_key
         
     | 
| 44 | 
         | 
| 45 | 
         
             
                        answer = run_crew(question, file_name)
         
     | 
| 46 | 
         
             
                    except Exception as e:
         
     | 
| 
         | 
|
| 48 | 
         
             
                    finally:
         
     | 
| 49 | 
         
             
                        del os.environ["OPENAI_API_KEY"]
         
     | 
| 50 | 
         
             
                        del os.environ["GEMINI_API_KEY"]
         
     | 
| 51 | 
         
            +
                        del os.environ["ANTHROPIC_API_KEY"]
         
     | 
| 52 | 
         | 
| 53 | 
         
             
                    return answer
         
     | 
| 54 | 
         | 
| 
         | 
|
| 87 | 
         
             
                                label="Gemini API Key *",
         
     | 
| 88 | 
         
             
                                type="password"
         
     | 
| 89 | 
         
             
                            )
         
     | 
| 90 | 
         
            +
                            anthropic_api_key = gr.Textbox(
         
     | 
| 91 | 
         
            +
                                label="Anthropic API Key *",
         
     | 
| 92 | 
         
            +
                                type="password"
         
     | 
| 93 | 
         
            +
                            )
         
     | 
| 94 | 
         
             
                        with gr.Row():
         
     | 
| 95 | 
         
             
                            clear_btn = gr.ClearButton(
         
     | 
| 96 | 
         
            +
                                components=[question, level, ground_truth, file_name]
         
     | 
| 97 | 
         
             
                            )
         
     | 
| 98 | 
         
             
                            submit_btn = gr.Button("Submit", variant="primary")
         
     | 
| 99 | 
         
             
                    with gr.Column(scale=1):
         
     | 
| 
         | 
|
| 105 | 
         | 
| 106 | 
         
             
                submit_btn.click(
         
     | 
| 107 | 
         
             
                    fn=_run,
         
     | 
| 108 | 
         
            +
                    inputs=[question, openai_api_key, gemini_api_key, anthropic_api_key, file_name],
         
     | 
| 109 | 
         
             
                    outputs=answer
         
     | 
| 110 | 
         
             
                )
         
     | 
| 111 | 
         | 
| 
         | 
|
| 114 | 
         
             
                gr.Examples(
         
     | 
| 115 | 
         
             
                    label="Level 1",
         
     | 
| 116 | 
         
             
                    examples=get_questions(QUESTION_FILE_PATH, 1),
         
     | 
| 117 | 
         
            +
                    inputs=[question, level, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
         
     | 
| 118 | 
         
             
                    outputs=answer,
         
     | 
| 119 | 
         
             
                    cache_examples=False
         
     | 
| 120 | 
         
             
                )
         
     | 
| 
         | 
|
| 122 | 
         
             
                gr.Examples(
         
     | 
| 123 | 
         
             
                    label="Level 2",
         
     | 
| 124 | 
         
             
                    examples=get_questions(QUESTION_FILE_PATH, 2),
         
     | 
| 125 | 
         
            +
                    inputs=[question, level, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
         
     | 
| 126 | 
         
             
                    outputs=answer,
         
     | 
| 127 | 
         
             
                    cache_examples=False
         
     | 
| 128 | 
         
             
                )
         
     | 
| 
         | 
|
| 130 | 
         
             
                gr.Examples(
         
     | 
| 131 | 
         
             
                    label="Level 3",
         
     | 
| 132 | 
         
             
                    examples=get_questions(QUESTION_FILE_PATH, 3),
         
     | 
| 133 | 
         
            +
                    inputs=[question, level, ground_truth, file_name, openai_api_key, gemini_api_key, anthropic_api_key],
         
     | 
| 134 | 
         
             
                    outputs=answer,
         
     | 
| 135 | 
         
             
                    cache_examples=False
         
     | 
| 136 | 
         
             
                )
         
     |