forked from martinthomson/ohttp
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdemo.py
More file actions
executable file
·64 lines (53 loc) · 2.04 KB
/
demo.py
File metadata and controls
executable file
·64 lines (53 loc) · 2.04 KB
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
import streamlit as st
import pandas as pd
import jwt
import subprocess
import os
import time
import json
import requests
import urllib3
urllib3.disable_warnings()
def run_and_display_stdout(*cmd_with_args, cwd):
result = subprocess.Popen(cmd_with_args, stdout=subprocess.PIPE, cwd=cwd)
results = False
for line in iter(lambda: result.stdout.readline(), b""):
str = line.decode('utf-8')
print(str.strip())
if str.startswith("Loaded"):
print(" (press key to continue to step 2)")
time.sleep(10)
if "\"text\"" in str or results:
out = json.loads(str)
yield out["text"]
time.sleep(0.02)
def attest(col):
response = requests.get('https://confwhispertest.openai.azure.com:9443/discover', verify=False)
claims = jwt.decode(response.content, options={"verify_signature": False})
df = []
for claim, value in claims.items():
if claim == "x-ms-isolation-tee" or claim == "x-ms-runtime":
for k,v in value.items():
df.append({"claim": claim+"."+k, "value": str(v)})
else:
df.append({"claim":claim, "value": str(value)})
with col:
st.dataframe(pd.DataFrame(df), height=500, use_container_width=True)
def main():
st.set_page_config (layout="wide")
st.title('Sample Confidential Whisper Application')
audio_file = st.file_uploader("Upload audio", type=["mp3","wav"])
global col1
col1, col2 = st.columns(2)
if audio_file is not None:
with open(audio_file.name,"wb") as f:
f.write((audio_file).getbuffer())
os.environ['INPUT'] = audio_file.name
with col1:
st.header("Attestation information")
with col2:
st.header("Transcription result")
col2.write_stream(run_and_display_stdout("target/debug/ohttp-client", "--kms-cert","examples/kms.pem","-i",audio_file.name, "https://confwhispertest.openai.azure.com:9443/score", cwd="."))
attest(col1)
if __name__ == "__main__":
main()