Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -50,33 +50,34 @@ def api_calling(audio_file, prompt, api_key):
|
|
50 |
audio_text = record_text(audio_file,api_key)
|
51 |
if len(prompt) == 0:
|
52 |
prompt = "Apply proper punctuations, upper case and lower case to the provided text."
|
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 |
|
|
|
50 |
audio_text = record_text(audio_file,api_key)
|
51 |
if len(prompt) == 0:
|
52 |
prompt = "Apply proper punctuations, upper case and lower case to the provided text."
|
53 |
+
return audio_text
|
54 |
+
else:
|
55 |
+
headers = {
|
56 |
+
"Content-Type": "application/json",
|
57 |
+
"Authorization": f"Bearer {api_key}"
|
58 |
+
}
|
59 |
+
payload = {
|
60 |
+
"model": "gpt-3.5-turbo",
|
61 |
+
"messages": [
|
62 |
+
{
|
63 |
+
"role": "user",
|
64 |
+
"content": [
|
65 |
+
{
|
66 |
+
"type": "text",
|
67 |
+
"text": prompt
|
68 |
+
},
|
69 |
+
{
|
70 |
+
"type": "text",
|
71 |
+
"text": audio_text
|
72 |
+
}
|
73 |
+
]
|
74 |
+
}
|
75 |
+
],
|
76 |
+
"max_tokens": 1000
|
77 |
+
}
|
78 |
+
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
|
79 |
+
audio_text_res = response.json()
|
80 |
+
return audio_text_res["choices"][0]["message"]["content"]
|
81 |
|
82 |
|
83 |
|