sylvain471's picture
Upload 2 files
c9d6090 verified
raw
history blame
3.46 kB
import gradio as gr
from scrape_fake_app import get_homework,get_timetable
import subprocess
import os
from dotenv import load_dotenv
if os.getenv('ENVIRONMENT')=="PROD":
print("installing playwright firefox")
subprocess.run(["playwright","install","firefox"])
def fetch_homework(date:str,request: gr.Request) -> str:
"""
description:
fetch the homeworks.
Args:
date: (str) set it to "today" unless explicitly specified otherwise
Returns:
The string describing the homeworks
"""
# print(str(dict(request.headers)["token"]))
token = str(dict(request.headers)["token"])
return get_homework(token)
def fetch_timetable(date:str,request: gr.Request) -> str:
"""
description:
fetch the timetable
Args:
date: (str) set it to "today" unless explicitly specified otherwise
Returns:
The string describing the timetable
"""
# print(str(dict(request.headers)["token"]))
token = str(dict(request.headers)["token"])
return get_timetable(token)
title="<h2>Gradio MCP Hackathon: fake-app-scraper</h2>"
description = """<div style="font-family: sans-serif; line-height: 1.6;">
<p>
This app uses Playwright to log in and scrape the content of the dashboard of the fake app
<a href="https://fake-app-omega.vercel.app" target="_blank">fake-app-omega.vercel.app</a>.
</p>
<p>
The url, username and password to log in to the fake-app dashboard are passed to the mcp-server via a token in the request header.
</p>
<p>
Clicking on "Homeworks" or "Timetable" will produce an ERROR as no token is given here
</p>
<p>
You can test the mcp-server tools in Claude desktop using the following mcp-server config
</p>
</div>
"""
images="""<img src="gradio_api/file=login.png" alt="login" style="max-width: 35%; margin-right: 10px;" />
<img src="gradio_api/file=dashboard.png" alt="dashboard" style="max-width: 35%;" />
"""
with gr.Blocks() as demo:
with gr.Row():
gr.HTML(title)
with gr.Row():
with gr.Column():
homeworks_btn = gr.Button("Homeworks")
homeworks_output = gr.Textbox(label="Homeworks Result", lines=5)
with gr.Column():
timetable_btn = gr.Button("Timetable")
timetable_output = gr.Textbox(label="Timetable Result", lines=5)
with gr.Row():
date = gr.Textbox(label="date",visible=False)
with gr.Row():
gr.HTML(description)
gr.JSON(
{
"mcpServers": {
"gradio": {
"command": "npx",
"args": [
"mcp-remote",
"https://agents-mcp-hackathon-fake-app-scraper.hf.space/gradio_api/mcp/sse",
"--header",
"token:aHR0cHM6Ly9mYWtlLWFwcC1vbWVnYS52ZXJjZWwuYXBwL2xvZ2luPHNlcD5ncmFkaW88c2VwPm1jcA==",
],
}
}
}
)
with gr.Row():
gr.HTML(images)
homeworks_btn.click(fn=fetch_homework,
inputs=[date],
outputs=homeworks_output)
timetable_btn.click(fn=fetch_timetable,
inputs=[date],
outputs=timetable_output)
demo.launch(mcp_server=True,allowed_paths=["/"])