dennis111 commited on
Commit
5f08a22
·
1 Parent(s): fded0cb
Files changed (2) hide show
  1. app.py +2 -0
  2. app_playground.ipynb +92 -1
app.py CHANGED
@@ -175,6 +175,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
175
  content = file.content
176
  elif content_type == "text/x-python":
177
  content = file.content.decode("utf-8")
 
 
178
 
179
  if not task_id or question_text is None:
180
  print(f"Skipping item with missing task_id or question: {item}")
 
175
  content = file.content
176
  elif content_type == "text/x-python":
177
  content = file.content.decode("utf-8")
178
+ elif content_type == "audio/mpeg":
179
+ content = file.content
180
 
181
  if not task_id or question_text is None:
182
  print(f"Skipping item with missing task_id or question: {item}")
app_playground.ipynb CHANGED
@@ -1540,7 +1540,98 @@
1540
  "outputs": [],
1541
  "execution_count": null,
1542
  "source": "",
1543
- "id": "577b57828fda080f"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1544
  }
1545
  ],
1546
  "metadata": {
 
1540
  "outputs": [],
1541
  "execution_count": null,
1542
  "source": "",
1543
+ "id": "61af75adbc305848"
1544
+ },
1545
+ {
1546
+ "metadata": {
1547
+ "ExecuteTime": {
1548
+ "end_time": "2025-04-30T13:30:30.256759Z",
1549
+ "start_time": "2025-04-30T13:30:02.301925Z"
1550
+ }
1551
+ },
1552
+ "cell_type": "code",
1553
+ "source": [
1554
+ "question = \"\"\"Hi, I'm making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I'm not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can't quite make out what she's saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I've attached the recipe as Strawberry pie.mp3.\\n\\nIn your response, please only list the ingredients, not any measurements. So if the recipe calls for \"a pinch of salt\" or \"two cups of ripe strawberries\" the ingredients on the list would be \"salt\" and \"ripe strawberries\".\\n\\nPlease format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.\"\"\"\n",
1555
+ "\n",
1556
+ "\n",
1557
+ "url = \"https://agents-course-unit4-scoring.hf.space\"\n",
1558
+ "task_id = \"99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3\"\n",
1559
+ "\n",
1560
+ "content = requests.get(f\"{url}/files/{task_id}\").content\n",
1561
+ "\n",
1562
+ "\n",
1563
+ "load_dotenv()\n",
1564
+ "# --- Temporäre Datei erstellen und Bytes schreiben ---\n",
1565
+ "temp_file_path = None\n",
1566
+ "try:\n",
1567
+ " # Erstelle eine benannte temporäre Datei mit der Endung .mp3\n",
1568
+ " # delete=False sorgt dafür, dass die Datei nicht sofort gelöscht wird,\n",
1569
+ " # wenn der 'with'-Block verlassen wird. Wir löschen sie manuell.\n",
1570
+ " with tempfile.NamedTemporaryFile(suffix=\".mp3\", delete=False) as temp_audio_file:\n",
1571
+ " temp_audio_file.write(content)\n",
1572
+ " temp_file_path = temp_audio_file.name # Hol den Pfad zur temporären Datei\n",
1573
+ "\n",
1574
+ " print(f\"MP3-Inhalt wurde temporär gespeichert unter: {temp_file_path}\")\n",
1575
+ " aai.settings.api_key = os.environ[\"ASSEMBLYAI_API_KEY\"]\n",
1576
+ "\n",
1577
+ " loader = AssemblyAIAudioTranscriptLoader(file_path=temp_file_path)\n",
1578
+ "\n",
1579
+ " docs = loader.load()\n",
1580
+ " transcript = \"\\n\\n\".join(\n",
1581
+ " (f\"\\nTranscript:\\n{doc.page_content}\")\n",
1582
+ " for doc in docs\n",
1583
+ " )\n",
1584
+ " response = graph.invoke({\"messages\": [HumanMessage(content=question), HumanMessage(content=transcript),]})\n",
1585
+ "\n",
1586
+ "finally:\n",
1587
+ " # --- Temporäre Datei aufräumen ---\n",
1588
+ " if temp_file_path and os.path.exists(temp_file_path):\n",
1589
+ " print(f\"Lösche temporäre Datei: {temp_file_path}\")\n",
1590
+ " os.remove(temp_file_path)"
1591
+ ],
1592
+ "id": "577b57828fda080f",
1593
+ "outputs": [
1594
+ {
1595
+ "name": "stdout",
1596
+ "output_type": "stream",
1597
+ "text": [
1598
+ "MP3-Inhalt wurde temporär gespeichert unter: C:\\Users\\DENNIS~1.BIN\\AppData\\Local\\Temp\\tmpwi8s8ny2.mp3\n",
1599
+ "\n",
1600
+ "-------------------- Starting to create a plan --------------------\n",
1601
+ "\n",
1602
+ "The plan is: 1. Extract the ingredients from the transcript.\n",
1603
+ "2. Remove any quantities or adjectives from the ingredients.\n",
1604
+ "3. Alphabetize the ingredients.\n",
1605
+ "4. Format the ingredients as a comma-separated list.\n",
1606
+ "\n",
1607
+ "-------------------- Agent has been called -----------------------------------\n",
1608
+ "\n",
1609
+ "Waiting for 5 seconds...\n",
1610
+ "Agent has made a decision:\n",
1611
+ " cornstarch, granulated sugar, lemon juice, ripe strawberries, vanilla extract []\n",
1612
+ "\n",
1613
+ "-------------------- Decision of forwarding has been made --------------------\n",
1614
+ "\n",
1615
+ "This is round: 2\n",
1616
+ "The last message is: content='cornstarch, granulated sugar, lemon juice, ripe strawberries, vanilla extract' additional_kwargs={} response_metadata={'prompt_feedback': {'block_reason': 0, 'safety_ratings': []}, 'finish_reason': 'STOP', 'model_name': 'gemini-2.0-flash', 'safety_ratings': []} id='run-5f798ac5-3001-4442-8b03-5cf6afedf416-0' usage_metadata={'input_tokens': 819, 'output_tokens': 15, 'total_tokens': 834, 'input_token_details': {'cache_read': 0}}\n",
1617
+ "\n",
1618
+ "-------------------- Generating Answer -----------------------------------\n",
1619
+ "\n",
1620
+ "Waiting for 5 seconds...\n",
1621
+ "The final answer is: cornstarch, granulated sugar, lemon juice, ripe strawberries, vanilla extract\n",
1622
+ "Lösche temporäre Datei: C:\\Users\\DENNIS~1.BIN\\AppData\\Local\\Temp\\tmpwi8s8ny2.mp3\n"
1623
+ ]
1624
+ }
1625
+ ],
1626
+ "execution_count": 22
1627
+ },
1628
+ {
1629
+ "metadata": {},
1630
+ "cell_type": "code",
1631
+ "outputs": [],
1632
+ "execution_count": null,
1633
+ "source": "",
1634
+ "id": "172512566b7e69ad"
1635
  }
1636
  ],
1637
  "metadata": {