Yasu777 commited on
Commit
3f2c65f
·
verified ·
1 Parent(s): 2efcbd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -3,6 +3,23 @@ import os
3
  from groq import Groq
4
  import re
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  # APIキーの設定
7
  try:
8
  client = Groq(api_key=st.secrets["GROQ_API_KEY"])
@@ -139,20 +156,3 @@ if st.button("会話をリセット"):
139
  if st.checkbox("デバッグ情報を表示"):
140
  st.write("会話履歴:", st.session_state['conversation_history'])
141
  st.write("API Key設定状況:", "設定済み" if "GROQ_API_KEY" in st.secrets else "未設定")
142
-
143
- # コードブロックを抽出する関数
144
- def extract_code_blocks(text):
145
- # 三重バッククォートで囲まれた部分を抽出
146
- return re.findall(r'```.*?```', text, re.DOTALL)
147
-
148
- # 非コード部分からコードブロックを取り除く関数
149
- def remove_code_blocks(text):
150
- # コードブロックを取り除いたテキストを返す処理
151
- return re.sub(r'```.*?```', '', text, flags=re.DOTALL)
152
-
153
- # コードブロックを再挿入する関数
154
- def reinsert_code_blocks(translated_text, code_blocks):
155
- # コードブロックを適切な位置に戻す処理
156
- for block in code_blocks:
157
- translated_text += f'\n\n{block}'
158
- return translated_text
 
3
  from groq import Groq
4
  import re
5
 
6
+ # コードブロックを抽出する関数
7
+ def extract_code_blocks(text):
8
+ # 三重バッククォートで囲まれた部分を抽出
9
+ return re.findall(r'```.*?```', text, re.DOTALL)
10
+
11
+ # 非コード部分からコードブロックを取り除く関数
12
+ def remove_code_blocks(text):
13
+ # コードブロックを取り除いたテキストを返す処理
14
+ return re.sub(r'```.*?```', '', text, flags=re.DOTALL)
15
+
16
+ # コードブロックを再挿入する関数
17
+ def reinsert_code_blocks(translated_text, code_blocks):
18
+ # コードブロックを適切な位置に戻す処理
19
+ for block in code_blocks:
20
+ translated_text += f'\n\n{block}'
21
+ return translated_text
22
+
23
  # APIキーの設定
24
  try:
25
  client = Groq(api_key=st.secrets["GROQ_API_KEY"])
 
156
  if st.checkbox("デバッグ情報を表示"):
157
  st.write("会話履歴:", st.session_state['conversation_history'])
158
  st.write("API Key設定状況:", "設定済み" if "GROQ_API_KEY" in st.secrets else "未設定")