-
Notifications
You must be signed in to change notification settings - Fork 2
/
proxy.py
68 lines (49 loc) · 1.69 KB
/
proxy.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
from fastapi import FastAPI
from uagents import Model
from uagents.query import query
import requests, json, asyncio, time
from typing import Optional
def make_get_request(base_url):
music_prompt_url = f"{base_url}/audio"
response = requests.get(music_prompt_url)
if response:
file_path = response.json()
# Open the text file and read its contents
try:
print("file_path: " + str(file_path))
with open(file_path, "r") as file:
content = file.read()
except FileNotFoundError:
print("Error: The file does not exist.")
except Exception as e:
print(f"An error occurred: {e}")
print(str(content))
return
def make_post_request(base_url):
latitude = 34.0156229728407
longitude = -118.49441383847054
radius = 10.0
coord_url = f"{base_url}/location/?latitude={latitude}&longitude={longitude}&radius={radius}"
response = requests.post(coord_url)
print(response)
return
with open(file_path, "rb") as audio_file:
files = {"file": (file_path, audio_file, "audio/wav")}
# Sending a POST request with the file
response = requests.post(url, files=files)
# Checking if the request was successful
if response.status_code == 200:
print("Request successful!")
print("Response content:")
print(response.text) # Printing the content of the response
else:
print(f"Request failed with status code: {response.status_code}")
def main():
base_url = "http://192.168.61.134:4000/api"
file_path = "test.wav"
while True:
time.sleep(5)
make_get_request(base_url)
time.sleep(5)
if __name__ == "__main__":
main()