dennis111 commited on
Commit
1be50f1
·
1 Parent(s): d4ba1d5
Files changed (4) hide show
  1. agent.py +2 -0
  2. app.py +33 -0
  3. app_playground.ipynb +185 -0
  4. playground_api.ipynb +7 -7
agent.py CHANGED
@@ -207,6 +207,8 @@ def get_graph(llm):
207
  )
208
  return {"youtube_transcript": transcript}
209
 
 
 
210
  tools = [wiki_search, web_search, arvix_search, youtube_transcript, multiply, add, subtract, divide, modulus]
211
  tool_node = ToolNode(tools)
212
  llm_with_tools = llm.bind_tools(tools)
 
207
  )
208
  return {"youtube_transcript": transcript}
209
 
210
+
211
+
212
  tools = [wiki_search, web_search, arvix_search, youtube_transcript, multiply, add, subtract, divide, modulus]
213
  tool_node = ToolNode(tools)
214
  llm_with_tools = llm.bind_tools(tools)
app.py CHANGED
@@ -1,4 +1,6 @@
1
  import os
 
 
2
  import gradio as gr
3
  import requests
4
  import inspect
@@ -8,6 +10,9 @@ import json
8
  import time
9
  import base64
10
 
 
 
 
11
  from agent import *
12
 
13
  # (Keep Constants as is)
@@ -59,6 +64,34 @@ class BasicAgent:
59
  ]
60
  # Invoke the graph with the code
61
  response = self.graph.invoke({"messages": [HumanMessage(content=question_with_code),]})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  else :
63
  # Invoke the graph with the question
64
  response = self.graph.invoke({"messages": [HumanMessage(content=question),]})
 
1
  import os
2
+ import tempfile
3
+
4
  import gradio as gr
5
  import requests
6
  import inspect
 
10
  import time
11
  import base64
12
 
13
+ from langchain_community.document_loaders import AssemblyAIAudioTranscriptLoader
14
+ import assemblyai as aai
15
+
16
  from agent import *
17
 
18
  # (Keep Constants as is)
 
64
  ]
65
  # Invoke the graph with the code
66
  response = self.graph.invoke({"messages": [HumanMessage(content=question_with_code),]})
67
+ elif content_type == "audio/mpeg":
68
+ # --- Temporäre Datei erstellen und Bytes schreiben ---
69
+ temp_file_path = None
70
+ try:
71
+ # Erstelle eine benannte temporäre Datei mit der Endung .mp3
72
+ # delete=False sorgt dafür, dass die Datei nicht sofort gelöscht wird,
73
+ # wenn der 'with'-Block verlassen wird. Wir löschen sie manuell.
74
+ with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_audio_file:
75
+ temp_audio_file.write(content)
76
+ temp_file_path = temp_audio_file.name # Hol den Pfad zur temporären Datei
77
+
78
+ print(f"MP3-Inhalt wurde temporär gespeichert unter: {temp_file_path}")
79
+ aai.settings.api_key = os.environ["ASSEMBLYAI_API_KEY"]
80
+
81
+ loader = AssemblyAIAudioTranscriptLoader(file_path=temp_file_path)
82
+
83
+ docs = loader.load()
84
+ transcript = "\n\n".join(
85
+ (f"\nTranscript:\n{doc.page_content}")
86
+ for doc in docs
87
+ )
88
+ response = self.graph.invoke({"messages": [HumanMessage(content=question), HumanMessage(content=transcript),]})
89
+
90
+ finally:
91
+ # --- Temporäre Datei aufräumen ---
92
+ if temp_file_path and os.path.exists(temp_file_path):
93
+ print(f"Lösche temporäre Datei: {temp_file_path}")
94
+ os.remove(temp_file_path)
95
  else :
96
  # Invoke the graph with the question
97
  response = self.graph.invoke({"messages": [HumanMessage(content=question),]})
app_playground.ipynb CHANGED
@@ -1356,6 +1356,191 @@
1356
  "execution_count": null,
1357
  "source": "",
1358
  "id": "993e1e7a8ec05fff"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1359
  }
1360
  ],
1361
  "metadata": {
 
1356
  "execution_count": null,
1357
  "source": "",
1358
  "id": "993e1e7a8ec05fff"
1359
+ },
1360
+ {
1361
+ "metadata": {},
1362
+ "cell_type": "markdown",
1363
+ "source": "# Assembly AI",
1364
+ "id": "6df1762bcce7593e"
1365
+ },
1366
+ {
1367
+ "metadata": {
1368
+ "ExecuteTime": {
1369
+ "end_time": "2025-04-30T12:55:07.171820Z",
1370
+ "start_time": "2025-04-30T12:55:07.155179Z"
1371
+ }
1372
+ },
1373
+ "cell_type": "code",
1374
+ "source": [
1375
+ "import requests\n",
1376
+ "from langchain_community.document_loaders import AssemblyAIAudioTranscriptLoader\n",
1377
+ "import assemblyai as aai\n",
1378
+ "import tempfile\n",
1379
+ "import os\n",
1380
+ "from dotenv import load_dotenv\n",
1381
+ "\n",
1382
+ "load_dotenv()\n"
1383
+ ],
1384
+ "id": "e27e107d54b381df",
1385
+ "outputs": [
1386
+ {
1387
+ "data": {
1388
+ "text/plain": [
1389
+ "True"
1390
+ ]
1391
+ },
1392
+ "execution_count": 15,
1393
+ "metadata": {},
1394
+ "output_type": "execute_result"
1395
+ }
1396
+ ],
1397
+ "execution_count": 15
1398
+ },
1399
+ {
1400
+ "metadata": {
1401
+ "ExecuteTime": {
1402
+ "end_time": "2025-04-30T12:40:28.602601Z",
1403
+ "start_time": "2025-04-30T12:40:16.914256Z"
1404
+ }
1405
+ },
1406
+ "cell_type": "code",
1407
+ "source": [
1408
+ "url = \"https://agents-course-unit4-scoring.hf.space\"\n",
1409
+ "task_id = \"99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3\"\n",
1410
+ "\n",
1411
+ "qs = requests.get(f\"{url}/questions\").json()\n",
1412
+ "\n",
1413
+ "file = requests.get(f\"{url}/files/{task_id}\").content\n"
1414
+ ],
1415
+ "id": "aac5535533ce0799",
1416
+ "outputs": [],
1417
+ "execution_count": 6
1418
+ },
1419
+ {
1420
+ "metadata": {
1421
+ "ExecuteTime": {
1422
+ "end_time": "2025-04-30T12:46:33.635917Z",
1423
+ "start_time": "2025-04-30T12:46:33.146187Z"
1424
+ }
1425
+ },
1426
+ "cell_type": "code",
1427
+ "source": [
1428
+ "# --- Dein Code zum Abrufen der Datei ---\n",
1429
+ "url = \"https://agents-course-unit4-scoring.hf.space\"\n",
1430
+ "task_id = \"99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3\"\n",
1431
+ "\n",
1432
+ "try:\n",
1433
+ " response = requests.get(f\"{url}/files/{task_id}\")\n",
1434
+ " response.raise_for_status() # Stellt sicher, dass der Request erfolgreich war (Status Code 2xx)\n",
1435
+ " mp3_content = response.content\n",
1436
+ "except requests.exceptions.RequestException as e:\n",
1437
+ " print(f\"Fehler beim Abrufen der MP3-Datei: {e}\")\n",
1438
+ " exit() # Beenden, wenn die Datei nicht geladen werden konnte"
1439
+ ],
1440
+ "id": "ee9a1a4c4697a386",
1441
+ "outputs": [],
1442
+ "execution_count": 9
1443
+ },
1444
+ {
1445
+ "metadata": {
1446
+ "ExecuteTime": {
1447
+ "end_time": "2025-04-30T12:56:11.668787Z",
1448
+ "start_time": "2025-04-30T12:56:06.012180Z"
1449
+ }
1450
+ },
1451
+ "cell_type": "code",
1452
+ "source": [
1453
+ "# --- Temporäre Datei erstellen und Bytes schreiben ---\n",
1454
+ "temp_file_path = None\n",
1455
+ "try:\n",
1456
+ " # Erstelle eine benannte temporäre Datei mit der Endung .mp3\n",
1457
+ " # delete=False sorgt dafür, dass die Datei nicht sofort gelöscht wird,\n",
1458
+ " # wenn der 'with'-Block verlassen wird. Wir löschen sie manuell.\n",
1459
+ " with tempfile.NamedTemporaryFile(suffix=\".mp3\", delete=False) as temp_audio_file:\n",
1460
+ " temp_audio_file.write(mp3_content)\n",
1461
+ " temp_file_path = temp_audio_file.name # Hol den Pfad zur temporären Datei\n",
1462
+ "\n",
1463
+ " print(f\"MP3-Inhalt wurde temporär gespeichert unter: {temp_file_path}\")\n",
1464
+ " aai.settings.api_key = os.environ[\"ASSEMBLYAI_API_KEY\"]\n",
1465
+ "\n",
1466
+ " loader = AssemblyAIAudioTranscriptLoader(file_path=temp_file_path)\n",
1467
+ "\n",
1468
+ " docs = loader.load()\n",
1469
+ "\n",
1470
+ "finally:\n",
1471
+ " # --- Temporäre Datei aufräumen ---\n",
1472
+ " if temp_file_path and os.path.exists(temp_file_path):\n",
1473
+ " print(f\"Lösche temporäre Datei: {temp_file_path}\")\n",
1474
+ " os.remove(temp_file_path)"
1475
+ ],
1476
+ "id": "55017338ea90f3a",
1477
+ "outputs": [
1478
+ {
1479
+ "name": "stdout",
1480
+ "output_type": "stream",
1481
+ "text": [
1482
+ "MP3-Inhalt wurde temporär gespeichert unter: C:\\Users\\DENNIS~1.BIN\\AppData\\Local\\Temp\\tmp9hggjvry.mp3\n",
1483
+ "Lösche temporäre Datei: C:\\Users\\DENNIS~1.BIN\\AppData\\Local\\Temp\\tmp9hggjvry.mp3\n"
1484
+ ]
1485
+ }
1486
+ ],
1487
+ "execution_count": 17
1488
+ },
1489
+ {
1490
+ "metadata": {
1491
+ "ExecuteTime": {
1492
+ "end_time": "2025-04-30T12:57:50.890823Z",
1493
+ "start_time": "2025-04-30T12:57:50.885966Z"
1494
+ }
1495
+ },
1496
+ "cell_type": "code",
1497
+ "source": [
1498
+ "for doc in docs:\n",
1499
+ " print(doc.page_content)"
1500
+ ],
1501
+ "id": "51672ebf8ed917fb",
1502
+ "outputs": [
1503
+ {
1504
+ "name": "stdout",
1505
+ "output_type": "stream",
1506
+ "text": [
1507
+ "In a saucepan, combine ripe strawberries, granulated sugar, freshly squeezed lemon juice and cornstarch. Cook the mixture over medium heat, stirring constantly, until it thickens to a smooth consistency. Remove from heat and stir in a dash of pure vanilla extract. Allow the strawberry pie filling to cool before using it as a delicious and fruity filling for your pie crust.\n"
1508
+ ]
1509
+ }
1510
+ ],
1511
+ "execution_count": 19
1512
+ },
1513
+ {
1514
+ "metadata": {
1515
+ "ExecuteTime": {
1516
+ "end_time": "2025-04-30T13:03:39.949969Z",
1517
+ "start_time": "2025-04-30T13:03:39.945166Z"
1518
+ }
1519
+ },
1520
+ "cell_type": "code",
1521
+ "source": "response.headers.get(\"Content-Type\")",
1522
+ "id": "cab3b9c717270399",
1523
+ "outputs": [
1524
+ {
1525
+ "data": {
1526
+ "text/plain": [
1527
+ "'audio/mpeg'"
1528
+ ]
1529
+ },
1530
+ "execution_count": 21,
1531
+ "metadata": {},
1532
+ "output_type": "execute_result"
1533
+ }
1534
+ ],
1535
+ "execution_count": 21
1536
+ },
1537
+ {
1538
+ "metadata": {},
1539
+ "cell_type": "code",
1540
+ "outputs": [],
1541
+ "execution_count": null,
1542
+ "source": "",
1543
+ "id": "577b57828fda080f"
1544
  }
1545
  ],
1546
  "metadata": {
playground_api.ipynb CHANGED
@@ -226,8 +226,8 @@
226
  {
227
  "metadata": {
228
  "ExecuteTime": {
229
- "end_time": "2025-04-28T20:05:01.953493Z",
230
- "start_time": "2025-04-28T20:05:01.925950Z"
231
  }
232
  },
233
  "cell_type": "code",
@@ -242,13 +242,13 @@
242
  ],
243
  "id": "799bcaab50ebff55",
244
  "outputs": [],
245
- "execution_count": 6
246
  },
247
  {
248
  "metadata": {
249
  "ExecuteTime": {
250
- "end_time": "2025-04-28T20:05:04.665088Z",
251
- "start_time": "2025-04-28T20:05:04.654871Z"
252
  }
253
  },
254
  "cell_type": "code",
@@ -495,12 +495,12 @@
495
  "</div>"
496
  ]
497
  },
498
- "execution_count": 7,
499
  "metadata": {},
500
  "output_type": "execute_result"
501
  }
502
  ],
503
- "execution_count": 7
504
  },
505
  {
506
  "metadata": {
 
226
  {
227
  "metadata": {
228
  "ExecuteTime": {
229
+ "end_time": "2025-04-30T13:04:59.351968Z",
230
+ "start_time": "2025-04-30T13:04:59.338937Z"
231
  }
232
  },
233
  "cell_type": "code",
 
242
  ],
243
  "id": "799bcaab50ebff55",
244
  "outputs": [],
245
+ "execution_count": 16
246
  },
247
  {
248
  "metadata": {
249
  "ExecuteTime": {
250
+ "end_time": "2025-04-30T13:04:59.536418Z",
251
+ "start_time": "2025-04-30T13:04:59.526232Z"
252
  }
253
  },
254
  "cell_type": "code",
 
495
  "</div>"
496
  ]
497
  },
498
+ "execution_count": 17,
499
  "metadata": {},
500
  "output_type": "execute_result"
501
  }
502
  ],
503
+ "execution_count": 17
504
  },
505
  {
506
  "metadata": {