janashraff commited on
Commit
caa6e5b
·
1 Parent(s): beaebc5

Initial deployment

Browse files
__pycache__/langchain.cpython-312.pyc ADDED
Binary file (1.79 kB). View file
 
app.py CHANGED
@@ -1,7 +1,126 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  demo.launch()
 
1
  import gradio as gr
2
+ import asyncio
3
+ import os
4
+ from langchain_mcp_adapters.client import MultiServerMCPClient
5
+ from langchain_google_genai import ChatGoogleGenerativeAI
6
+ from langchain.agents import create_agent
7
+ import tempfile
8
+ import shutil
9
+ # These automatically read from HF Secrets
10
+ GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
11
+ ELEVENLABS_API_KEY = os.environ.get("ELEVENLABS_API_KEY")
12
 
 
 
13
 
14
+ async def run_agent_dynamic(age: int, gender: str, topic: str, pdf_temp_path: str):
15
+ system_instruction = f"""
16
+ You are an autonomous teaching agent.
17
+ Your task:
18
+ - Create a short engaging audio story for a {age}-year-old {gender} student.
19
+ - The story should be based on the lecture PDF and the topic: "{topic}".
20
+ - Use simple English and emotion.
21
+ - Use any available tool to read content, write text, or generate audio.
22
+ - Do not ask the user how to do tasks. You must decide and act fully agentically.
23
+ """
24
+
25
+ client = MultiServerMCPClient({
26
+ "pdf-reader": {
27
+ "transport": "stdio",
28
+ "command": "D:\\MCP Hackathon\\PDF Extractor\\.venv\\Scripts\\python.exe",
29
+ "args": ["D:\\MCP Hackathon\\PDF Extractor\\mcp_pdf_reader\\src\\server.py"]
30
+ },
31
+ "ai-writer": {
32
+ "transport": "stdio",
33
+ "command": "D:\\MCP Hackathon\\PDF Extractor\\.venv\\Scripts\\python.exe",
34
+ "args": ["D:\\MCP Hackathon\\PDF Extractor\\ai_writers_workshop\\mcp_server\\server.py"]
35
+ },
36
+ "ElevenLabs": {
37
+ "transport": "stdio",
38
+ "command": "D:\\MCP Hackathon\\PDF Extractor\\elevenlabs-mcp\\.venv\\Scripts\\python.exe",
39
+ "args": ["D:\\MCP Hackathon\\PDF Extractor\\elevenlabs-mcp\\elevenlabs_mcp\\server.py"],
40
+ "env": {"ELEVENLABS_API_KEY": ELEVENLABS_API_KEY}
41
+ }
42
+ })
43
+
44
+ all_tools = []
45
+ seen = set()
46
+ for server_name in ["pdf-reader", "ai-writer", "ElevenLabs"]:
47
+ async with client.session(server_name):
48
+ tools = await client.get_tools()
49
+ for t in tools:
50
+ if t.name not in seen:
51
+ all_tools.append(t)
52
+ seen.add(t.name)
53
+
54
+ llm = ChatGoogleGenerativeAI(
55
+ model="gemini-2.5-flash",
56
+ google_api_key=GEMINI_API_KEY,
57
+ temperature=0.7
58
+ )
59
+
60
+ agent = create_agent(model=llm, tools=all_tools)
61
+
62
+ agent_input = {
63
+ "messages": [
64
+ {"role": "system", "content": system_instruction},
65
+ {
66
+ "role": "user",
67
+ "content": f"PDF_PATH: {pdf_temp_path}\n"
68
+ f"Please prepare the story and audio fully autonomously."
69
+ }
70
+ ]
71
+ }
72
+
73
+ result = await agent.ainvoke(agent_input)
74
+
75
+ return result
76
+
77
+
78
+ def gradio_handler(age, gender, topic, pdf_file):
79
+ if not pdf_file:
80
+ return "Please upload a PDF.", None
81
+
82
+ temp_dir = tempfile.mkdtemp()
83
+ pdf_path = os.path.join(temp_dir, "lecture.pdf")
84
+ shutil.copy(pdf_file, pdf_path)
85
+
86
+ try:
87
+ output = asyncio.run(run_agent_dynamic(age, gender, topic, pdf_path))
88
+ finally:
89
+ shutil.rmtree(temp_dir)
90
+
91
+ return str(output), None
92
+
93
+
94
+ with gr.Blocks() as demo:
95
+
96
+
97
+ gr.Markdown(
98
+ """
99
+ <h1 style='text-align:center;'>AI Educational Audio Story Generator</h1>
100
+ <p style='text-align:center; font-size:18px;'>
101
+ Provide student details and upload a lecture PDF.<br>
102
+ The agent will autonomously read, write, and produce audio.
103
+ </p>
104
+ """
105
+ )
106
+
107
+ with gr.Row():
108
+ age = gr.Number(label="Student Age", value=12)
109
+ gender = gr.Radio(["male", "female"], value="female", label="Student Gender")
110
+
111
+ topic = gr.Textbox(label="Topic / Concept", placeholder="Gravity, Weight, Mass...")
112
+
113
+ pdf_input = gr.File(label="Upload Lecture PDF", file_types=[".pdf"])
114
+
115
+ generate_btn = gr.Button("Generate Story & Audio", variant="primary")
116
+
117
+ output_text = gr.Textbox(label="Agent Output", lines=12)
118
+ audio_out = gr.Audio(label="Generated Audio")
119
+
120
+ generate_btn.click(
121
+ fn=gradio_handler,
122
+ inputs=[age, gender, topic, pdf_input],
123
+ outputs=[output_text, audio_out]
124
+ )
125
+
126
  demo.launch()
packages.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ tesseract-ocr
2
+ tesseract-ocr-eng
3
+ libtesseract-dev
4
+ poppler-utils
requirements.txt ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Main App Dependencies
2
+ gradio==4.44.0
3
+ langchain-mcp-adapters
4
+ langchain-google-genai
5
+ langchain
6
+ langchain-core
7
+ python-dotenv
8
+
9
+ # AI Writers Workshop Dependencies
10
+ fastmcp>=1.7.0
11
+ fastapi==0.109.2
12
+ uvicorn==0.27.1
13
+ pydantic>=2.6.1
14
+ httpx==0.28.1
15
+ mcp>=1.6.0
16
+ fuzzywuzzy==0.18.0
17
+ python-Levenshtein>=0.25.0
18
+ sounddevice==0.5.1
19
+ soundfile==0.13.1
20
+
21
+ # ElevenLabs Dependencies
22
+ elevenlabs>=2.13.0
23
+
24
+ # MCP PDF Reader Server Dependencies
25
+ PyMuPDF>=1.23.0
26
+ pytesseract>=0.3.10
27
+ Pillow>=10.0.0
28
+
29
+ # Additional Common Dependencies
30
+ requests
31
+ aiohttp
32
+ asyncio
servers/__init__.py ADDED
File without changes
servers/ai_writers_workshop ADDED
@@ -0,0 +1 @@
 
 
1
+ Subproject commit c160a299706dd0cd1dc9ae114b97aba905e9261d
servers/elevenlabs-mcp ADDED
@@ -0,0 +1 @@
 
 
1
+ Subproject commit 280e4eae9bdb977d1a8c5d6f569edd2ad7af3c5e
servers/mcp_pdf_reader ADDED
@@ -0,0 +1 @@
 
 
1
+ Subproject commit 881052398052d2bfc68a0725ff013e8410e99e76