Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
with gr.Blocks() as gaia:
|
| 2 |
gr.HTML(f"<style>{CSS_FULL_WIDTH}</style>")
|
| 3 |
|
|
|
|
| 1 |
+
# References:
|
| 2 |
+
|
| 3 |
+
# https://www.gradio.app/guides/quickstart
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import gradio as gr
|
| 7 |
+
from agents.crew import run_crew
|
| 8 |
+
from utils.utils import get_questions
|
| 9 |
+
|
| 10 |
+
# Initialization
|
| 11 |
+
|
| 12 |
+
QUESTION_FILE_PATH_GAIA = "files/gaia_validation.jsonl"
|
| 13 |
+
QUESTION_FILE_PATH_HLE = "files/hle_validation.jsonl"
|
| 14 |
+
|
| 15 |
+
DEFAULT_QUESTION = "In MCP's 1st Birthday Hackathon, hosted by Anthropic and Gradio, what percentage of participants submitted a solution so far?"
|
| 16 |
+
|
| 17 |
+
# MCP server functions
|
| 18 |
+
|
| 19 |
+
def ask(question, openai_api_key, gemini_api_key, anthropic_api_key, file_name = ""):
|
| 20 |
+
"""
|
| 21 |
+
Ask General AI Assistant a question to answer.
|
| 22 |
+
|
| 23 |
+
Args:
|
| 24 |
+
question (str): The question to answer
|
| 25 |
+
openai_api_key (str): OpenAI API key
|
| 26 |
+
gemini_api_key (str): Gemini API key
|
| 27 |
+
anthropic_api_key (str): Anthropic API key
|
| 28 |
+
file_name (str): Optional file name
|
| 29 |
+
|
| 30 |
+
Returns:
|
| 31 |
+
str: The answer to the question
|
| 32 |
+
"""
|
| 33 |
+
if not question:
|
| 34 |
+
gr.Warning("Question is required.")
|
| 35 |
+
return ""
|
| 36 |
+
|
| 37 |
+
if not openai_api_key:
|
| 38 |
+
gr.Warning("OpenAI API Key is required.")
|
| 39 |
+
return ""
|
| 40 |
+
|
| 41 |
+
if not gemini_api_key:
|
| 42 |
+
gr.Warning("Gemini API Key is required.")
|
| 43 |
+
return ""
|
| 44 |
+
|
| 45 |
+
if not anthropic_api_key:
|
| 46 |
+
gr.Warning("Anthropic API Key is required.")
|
| 47 |
+
return ""
|
| 48 |
+
|
| 49 |
+
if file_name:
|
| 50 |
+
file_name = f"files/{file_name}"
|
| 51 |
+
|
| 52 |
+
try:
|
| 53 |
+
os.environ["OPENAI_API_KEY"] = openai_api_key
|
| 54 |
+
os.environ["GEMINI_API_KEY"] = gemini_api_key
|
| 55 |
+
os.environ["MODEL_API_KEY"] = anthropic_api_key
|
| 56 |
+
|
| 57 |
+
return run_crew(question, file_name)
|
| 58 |
+
except Exception as e:
|
| 59 |
+
gr.Warning(str(e))
|
| 60 |
+
return ""
|
| 61 |
+
finally:
|
| 62 |
+
for key in ["OPENAI_API_KEY", "GEMINI_API_KEY", "MODEL_API_KEY"]:
|
| 63 |
+
os.environ.pop(key, None)
|
| 64 |
+
|
| 65 |
+
# Helper functions
|
| 66 |
+
|
| 67 |
+
def update_file_link(file_name):
|
| 68 |
+
if file_name:
|
| 69 |
+
space_id = os.environ.get("SPACE_ID", "bstraehle/gaia")
|
| 70 |
+
base_url = f"https://huggingface.co/spaces/{space_id}/blob/main/files"
|
| 71 |
+
return f'<a href="{base_url}/{file_name}" target="_blank">Open File</a>'
|
| 72 |
+
|
| 73 |
+
return ""
|
| 74 |
+
|
| 75 |
+
# Graphical user interface
|
| 76 |
+
|
| 77 |
+
CSS_FULL_WIDTH = """
|
| 78 |
+
body {
|
| 79 |
+
margin: 0 !important;
|
| 80 |
+
}
|
| 81 |
+
.gradio-container {
|
| 82 |
+
max-width: 100% !important;
|
| 83 |
+
width: 100% !important;
|
| 84 |
+
margin: 0 !important;
|
| 85 |
+
padding-left: 0 !important;
|
| 86 |
+
padding-right: 0 !important;
|
| 87 |
+
}
|
| 88 |
+
.content-padding {
|
| 89 |
+
padding-left: 1.5rem;
|
| 90 |
+
padding-right: 1.5rem;
|
| 91 |
+
}
|
| 92 |
+
.full-width-tabs {
|
| 93 |
+
width: 100%;
|
| 94 |
+
}
|
| 95 |
+
.full-width-tabs .gradio-block {
|
| 96 |
+
max-width: 100%;
|
| 97 |
+
width: 100%;
|
| 98 |
+
}
|
| 99 |
+
"""
|
| 100 |
+
|
| 101 |
with gr.Blocks() as gaia:
|
| 102 |
gr.HTML(f"<style>{CSS_FULL_WIDTH}</style>")
|
| 103 |
|