{ "cells": [ { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import requests\n", "\n", "def infer_text(api_url, input_text):\n", " url = f\"{api_url}/infer\"\n", " try:\n", " # Send the input as a JSON object\n", " response = requests.post(url, json={\"input\": input_text})\n", " response.raise_for_status()\n", " return response.json()\n", " except requests.exceptions.RequestException as e:\n", " print(f\"Error during API call: {e}\")\n", " return None\n", "\n", "def check_health(api_url):\n", " url = f\"{api_url}/health\"\n", " try:\n", " response = requests.get(url)\n", " response.raise_for_status()\n", " return response.json()\n", " except requests.exceptions.RequestException as e:\n", " print(f\"Error during API health check: {e}\")\n", " return None" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "API Health Check: {'message': 'ok'}\n", "Predictions: [{'label': 'LABEL_0', 'score': 0.9927427768707275}]\n" ] } ], "source": [ "api_url = \"http://localhost:8000\"\n", "\n", "# Check the API health status\n", "health_status = check_health(api_url)\n", "if health_status:\n", " print(\"API Health Check:\", health_status)\n", "else:\n", " print(\"Failed to connect to the API.\")\n", "\n", "# Example input text\n", "input_text = \"Congratulations! You've won a prize. Click the link to claim your reward.\"\n", "\n", "# Call the /infer endpoint\n", "predictions = infer_text(api_url, input_text)\n", "if predictions:\n", " print(\"Predictions:\", predictions)\n", "else:\n", " print(\"Failed to get predictions from the API.\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "DeepFakeModel Test" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Response JSON: {'predicted_label': 'Real', 'average_confidence': 0.9984144032001495}\n" ] } ], "source": [ "import requests\n", "\n", "# Define the API endpoint\n", "url = \"http://127.0.0.1:8000/infer\"\n", "\n", "# Path to the audio file you want to test\n", "file_path = r\"D:\\repos\\GODAM\\audioFiles\\test.wav\" # Replace with the path to your audio file\n", "\n", "# Open the file in binary mode\n", "with open(file_path, \"rb\") as audio_file:\n", " # Prepare the file payload\n", " files = {\"file\": (\"audio.wav\", audio_file, \"audio/wav\")}\n", " \n", " # Send the POST request\n", " response = requests.post(url, files=files)\n", "\n", "# Print the response from the API\n", "if response.status_code == 200:\n", " print(\"Response JSON:\", response.json())\n", "else:\n", " print(f\"Error {response.status_code}: {response.text}\")" ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.7" } }, "nbformat": 4, "nbformat_minor": 2 }