-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPI_hit_first.py
96 lines (77 loc) · 3.74 KB
/
API_hit_first.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# import requests
# import subprocess
# import os
# # Replace with your Hugging Face Space's URL
# url = "http://127.0.0.1:5000/process-audio" # Use the updated endpoint
# # Path to your local video file
# video_file_path = "D:/COURSES/CGAS/Dish-Decode/fourth.mp4"
# # Path for the converted WAV file
# wav_file_path = video_file_path.replace(".mp4", ".wav")
# try:
# # Step 1: Convert MP4 to WAV using FFmpeg
# print("Converting video to audio (WAV format)...")
# ffmpeg_command = [
# "ffmpeg", "-i", video_file_path, "-q:a", "0", "-map", "a", wav_file_path
# ]
# subprocess.run(ffmpeg_command, check=True)
# print(f"Conversion successful! WAV file saved at: {wav_file_path}")
# # # # Step 2: Open the WAV file in binary mode and send the POST request
# # # with open(wav_file_path, "rb") as audio_file:
# # # print("Sending the WAV file in the POST request...")
# # # response = requests.post(url, files={"audio": audio_file}, timeout=600) # 10 mins
# # # # Step 3: Check the response
# # # if response.status_code == 200:
# # # print("Request successful! Here's the response:")
# # # print(response.json()) # If the API returns JSON data
# # # else:
# # # print(f"Error: Received status code {response.status_code}")
# # # print(response.text) # Print the error message if any
# except FileNotFoundError:
# print(f"Error: File not found at {video_file_path}")
# except subprocess.CalledProcessError as e:
# print(f"Error during conversion: {e}")
# except requests.exceptions.RequestException as e:
# print(f"An error occurred while making the request: {e}")
# finally:
# # Step 4: Clean up the WAV file after the request
# # # if os.path.exists(wav_file_path):
# # # os.remove(wav_file_path)
# print(f"Temporary WAV file deleted: {wav_file_path}")
# import requests
# # Replace with your Hugging Face Space's URL
# url = "https://goodml-dishdecode.hf.space/process-audio"
# # Cloudinary link to the audio file
# audio_url = "https://res.cloudinary.com/dqp1z12my/video/upload/v1733849188/third_rcflua.wav"
# # Beef wellington: https://res.cloudinary.com/dqp1z12my/video/upload/v1733814120/wznl6x77xomzzffujnjh.wav
# # Spiced Baked poridge: https://res.cloudinary.com/dqp1z12my/video/upload/v1733845697/tatta_a3skw0.wav
# # Spicy mexican eggs: https://res.cloudinary.com/dqp1z12my/video/upload/v1733849188/third_rcflua.wav
# # Tangy fruit salad":
# try:
# # Step 1: Send the Cloudinary link in a POST request
# print("Sending the audio URL in the POST request...")
# response = requests.post(url, json={"audioUrl": audio_url}, timeout=600) # Timeout set to 10 minutes
# # Step 2: Check the response
# if response.status_code == 200:
# print("Request successful! Here's the response:")
# print(response.json())
# else:
# print(f"Error: Received status code {response.status_code}")
# print(response.text)
# except requests.exceptions.RequestException as e:
# print(f"An error occurred while making the request: {e}")
import requests
# Define the URL of the Hugging Face Space
url = "https://goodml-dish-decode-2.hf.space/process-video"
# Define the payload data (the input for your model)
payload = {
'videoUrl': 'https://res.cloudinary.com/dqp1z12my/video/upload/v1734178209/thirdVideo_nlppqb.mp4' # Example of how to pass data to the model
}
# Send the POST request
response = requests.post(url, json=payload)
# Check the response status and content
if response.status_code == 200:
print("Request successful.")
print("Response:", response.json()) # Parse and print the JSON response
else:
print(f"Request failed with status code: {response.status_code}")
print("Error:", response.text)