Sabbah13 commited on
Commit
29a10e5
1 Parent(s): bd03d45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -40
app.py CHANGED
@@ -14,6 +14,9 @@ device = st.sidebar.selectbox("Device", ["cpu", "cuda"], index=1)
14
  batch_size = st.sidebar.number_input("Batch Size", min_value=1, value=16)
15
  compute_type = st.sidebar.selectbox("Compute Type", ["float16", "int8"], index=0)
16
 
 
 
 
17
  ACCESS_TOKEN = st.secrets["HF_TOKEN"]
18
 
19
  uploaded_file = st.file_uploader("Загрузите аудиофайл", type=["mp4", "wav", "m4a"])
@@ -46,54 +49,55 @@ if uploaded_file is not None:
46
  transcript = convert_segments_object_to_text(result_diar)
47
  st.text(transcript)
48
 
49
- with st.spinner('Резюмируем...'):
50
- username = st.secrets["GIGA_USERNAME"]
51
- password = st.secrets["GIGA_SECRET"]
 
52
 
53
- # Получаем строку с базовой авторизацией в формате Base64
54
- auth_str = f'{username}:{password}'
55
- auth_bytes = auth_str.encode('utf-8')
56
- auth_base64 = base64.b64encode(auth_bytes).decode('utf-8')
57
- url = os.getenv('GIGA_AUTH_URL')
58
 
59
- headers = {
60
- 'Authorization': f'Basic {auth_base64}', # вставляем базовую авторизацию
61
- 'RqUID': os.getenv('GIGA_rquid'),
62
- 'Content-Type': 'application/x-www-form-urlencoded',
63
- 'Accept': 'application/json'
64
- }
65
 
66
- data = {
67
- 'scope': os.getenv('GIGA_SCOPE')
68
- }
69
 
70
- response = requests.post(url, headers=headers, data=data, verify=False)
71
- access_token = response.json()['access_token']
72
- print('Got access token')
73
 
74
- url_completion = os.getenv('GIGA_COMPLETION_URL')
75
 
76
- data_copm = json.dumps({
77
- "model": os.getenv('GIGA_MODEL'),
78
- "messages": [
79
- {
80
- "role": "user",
81
- "content": os.getenv('GIGA_BASE_PROMPT') + transcript
82
- }
83
- ],
84
- "stream": False,
85
- "max_tokens": int(os.getenv('GIGA_MAX_TOKENS')),
86
- })
87
 
88
- headers_comp = {
89
- 'Content-Type': 'application/json',
90
- 'Accept': 'application/json',
91
- 'Authorization': 'Bearer ' + access_token
92
- }
93
 
94
- response = requests.post(url_completion, headers=headers_comp, data=data_copm, verify=False)
95
- response_data = response.json()
96
- answer_from_llm = response_data['choices'][0]['message']['content']
97
 
98
  st.write("Результат резюмирования:")
99
  st.text(answer_from_llm)
 
14
  batch_size = st.sidebar.number_input("Batch Size", min_value=1, value=16)
15
  compute_type = st.sidebar.selectbox("Compute Type", ["float16", "int8"], index=0)
16
 
17
+ giga_base_prompt = st.sidebar.text_area("Промпт ГигаЧата для резюмирования")
18
+ giga_max_tokens = st.sidebar.number_input("Максимальное количество токенов при ответе", min_value=1, value=2048)
19
+
20
  ACCESS_TOKEN = st.secrets["HF_TOKEN"]
21
 
22
  uploaded_file = st.file_uploader("Загрузите аудиофайл", type=["mp4", "wav", "m4a"])
 
49
  transcript = convert_segments_object_to_text(result_diar)
50
  st.text(transcript)
51
 
52
+ if st.button('Резюмировать'):
53
+ with st.spinner('Резюмируем...'):
54
+ username = st.secrets["GIGA_USERNAME"]
55
+ password = st.secrets["GIGA_SECRET"]
56
 
57
+ # Получаем строку с базовой авторизацией в формате Base64
58
+ auth_str = f'{username}:{password}'
59
+ auth_bytes = auth_str.encode('utf-8')
60
+ auth_base64 = base64.b64encode(auth_bytes).decode('utf-8')
61
+ url = os.getenv('GIGA_AUTH_URL')
62
 
63
+ headers = {
64
+ 'Authorization': f'Basic {auth_base64}', # вставляем базовую авторизацию
65
+ 'RqUID': os.getenv('GIGA_rquid'),
66
+ 'Content-Type': 'application/x-www-form-urlencoded',
67
+ 'Accept': 'application/json'
68
+ }
69
 
70
+ data = {
71
+ 'scope': os.getenv('GIGA_SCOPE')
72
+ }
73
 
74
+ response = requests.post(url, headers=headers, data=data, verify=False)
75
+ access_token = response.json()['access_token']
76
+ print('Got access token')
77
 
78
+ url_completion = os.getenv('GIGA_COMPLETION_URL')
79
 
80
+ data_copm = json.dumps({
81
+ "model": os.getenv('GIGA_MODEL'),
82
+ "messages": [
83
+ {
84
+ "role": "user",
85
+ "content": giga_base_prompt + transcript
86
+ }
87
+ ],
88
+ "stream": False,
89
+ "max_tokens": int(giga_max_tokens),
90
+ })
91
 
92
+ headers_comp = {
93
+ 'Content-Type': 'application/json',
94
+ 'Accept': 'application/json',
95
+ 'Authorization': 'Bearer ' + access_token
96
+ }
97
 
98
+ response = requests.post(url_completion, headers=headers_comp, data=data_copm, verify=False)
99
+ response_data = response.json()
100
+ answer_from_llm = response_data['choices'][0]['message']['content']
101
 
102
  st.write("Результат резюмирования:")
103
  st.text(answer_from_llm)