Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,6 +25,7 @@ def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[]
|
|
25 |
"max_tokens": 1000
|
26 |
}
|
27 |
|
|
|
28 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
29 |
|
30 |
partial_words = ""
|
@@ -35,23 +36,18 @@ def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[]
|
|
35 |
if chunk:
|
36 |
try:
|
37 |
chunk_text = chunk.decode()
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
if token_counter == 0:
|
45 |
-
history.append(" " + partial_words)
|
46 |
-
else:
|
47 |
-
history[-1] = partial_words
|
48 |
-
token_counter += 1
|
49 |
-
chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2)]
|
50 |
-
yield chat, history, chat_counter
|
51 |
except json.JSONDecodeError as e:
|
52 |
print("JSON ํ์ฑ ์ค๋ฅ:", e)
|
|
|
|
|
53 |
except Exception as e:
|
54 |
-
print("์๋ต ์ฒ๋ฆฌ ์ค๋ฅ:", e)
|
55 |
|
56 |
return chatbot, history, chat_counter
|
57 |
|
|
|
25 |
"max_tokens": 1000
|
26 |
}
|
27 |
|
28 |
+
|
29 |
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
30 |
|
31 |
partial_words = ""
|
|
|
36 |
if chunk:
|
37 |
try:
|
38 |
chunk_text = chunk.decode()
|
39 |
+
# JSON ํ์์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธ
|
40 |
+
if chunk_text.strip().startswith("{"):
|
41 |
+
chunk_data = json.loads(chunk_text) # JSON ํ์ฑ
|
42 |
+
# ... ๋๋จธ์ง ์ฝ๋ ...
|
43 |
+
else:
|
44 |
+
print("Unexpected format:", chunk_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
except json.JSONDecodeError as e:
|
46 |
print("JSON ํ์ฑ ์ค๋ฅ:", e)
|
47 |
+
except Exception as e:
|
48 |
+
print("์๋ต ์ฒ๋ฆฌ ์ค๋ฅ:", e)
|
49 |
except Exception as e:
|
50 |
+
print("์ ์ฒด ์๋ต ์ฒ๋ฆฌ ์ค๋ฅ:", e)
|
51 |
|
52 |
return chatbot, history, chat_counter
|
53 |
|