Spaces:
Sleeping
Sleeping
aahmed10202
commited on
Commit
•
dda9597
1
Parent(s):
60112e9
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
%%capture
|
2 |
+
!pip install transformers
|
3 |
+
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
from google.colab import files
|
7 |
+
uploaded = files.upload()
|
8 |
+
print(f"Uploaded files: {list(uploaded.keys())}")
|
9 |
+
|
10 |
+
from google.colab import userdata
|
11 |
+
my_key = userdata.get('key')
|
12 |
+
|
13 |
+
import requests
|
14 |
+
|
15 |
+
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3-turbo"
|
16 |
+
headers = {"Authorization": f"Bearer {my_key}"}
|
17 |
+
|
18 |
+
def query(filename):
|
19 |
+
filename = list(uploaded.keys())[0] # Get the uploaded file's nameprint("Uploaded filename:", filename)
|
20 |
+
with open(filename, "rb") as f:
|
21 |
+
data = f.read()
|
22 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
23 |
+
return response.json()
|
24 |
+
|
25 |
+
results = {}
|
26 |
+
for filename, file_data in uploaded.items():
|
27 |
+
# Save the file locally
|
28 |
+
with open(filename, "wb") as f:
|
29 |
+
f.write(file_data)
|
30 |
+
|
31 |
+
print(f"Sending {filename} to API...")
|
32 |
+
output = query(filename)
|
33 |
+
|
34 |
+
# Store the result
|
35 |
+
results[filename] = output
|
36 |
+
|
37 |
+
# Step 3: Print results
|
38 |
+
for file, result in results.items():
|
39 |
+
print(f"\nResults for {file}:\n{result}")
|