Spaces:
Sleeping
Sleeping
anisrashidov
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ import gradio as gr
|
|
11 |
from together import Together
|
12 |
|
13 |
load_dotenv("../.env")
|
14 |
-
print("Environment variables:", os.environ)
|
15 |
|
16 |
|
17 |
together_client = Together(
|
@@ -80,16 +80,8 @@ def get_naver_answers( message: str ):
|
|
80 |
print( "Query: ", query)
|
81 |
|
82 |
context = get_answers( query )
|
83 |
-
|
84 |
-
|
85 |
-
sorted_answers = []
|
86 |
-
for answer in context:
|
87 |
-
curr = '. '.join(answer['answers'])
|
88 |
-
answer_count += len(curr)
|
89 |
-
sorted_answers.append(curr)
|
90 |
-
if answer_count > 55000:
|
91 |
-
break
|
92 |
-
# sorted_answers = ['. '.join(answer['answers']) for answer in context]
|
93 |
naver_end_time = time.time()
|
94 |
print(f"Time taken to extract from Naver: { naver_end_time - naver_start_time } seconds")
|
95 |
document = '\n'.join(sorted_answers)
|
@@ -116,9 +108,10 @@ def get_qwen_small_answer( message: str ):
|
|
116 |
response = together_client.chat.completions.create(
|
117 |
model="Qwen/Qwen2.5-7B-Instruct-Turbo",
|
118 |
messages=[
|
119 |
-
{"role": "system", "content": "You are a helpful question-answer,
|
120 |
{"role": "user", "content": message}
|
121 |
-
]
|
|
|
122 |
#TODO: Change the messages option
|
123 |
)
|
124 |
qwen_end_time = time.time()
|
@@ -262,18 +255,29 @@ def compare_answers(message: str):
|
|
262 |
return results
|
263 |
|
264 |
def chatFunction( message, history ):
|
265 |
-
content = f'์๋ ๋ฌธ์๋ฅผ ๋ฐํ์ผ๋ก ์ง๋ฌธ์ ๋ตํ์ธ์. ๋ต๋ณ์์ ์ง๋ฌธ์ ๋ฐ๋ผ ์ถ๋ ฅ ํ์ง ๋ง์ธ์. ๋ต๋ณ์ ํ๊ตญ์ด๋ก๋ง ํด์ฃผ์ธ์! ์ฐพ์ Naver ๋ฌธ์์ ๋ค๋ฅธ ๋ฌธ์์์ ๋ต๋ณ์ด ์๋ ๋ด์ฉ์ ์ ๋ ์ถ๋ ฅํ์ง
|
266 |
naver_docs, naver_time_taken = get_naver_answers( message )
|
267 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
start_time = time.time()
|
269 |
content += "\n Naver ๋ฌธ์: " + naver_docs
|
270 |
|
271 |
-
print( ">>> Length: ", len(naver_docs) )
|
272 |
-
|
273 |
completion = gpt_client.chat.completions.create(
|
274 |
model="gpt-4o-mini",
|
275 |
messages=[
|
276 |
-
{"role": "system", "content": "You are a helpful assistant that answers only in korean."},
|
277 |
{
|
278 |
"role": "user",
|
279 |
"content": message
|
|
|
11 |
from together import Together
|
12 |
|
13 |
load_dotenv("../.env")
|
14 |
+
# print("Environment variables:", os.environ)
|
15 |
|
16 |
|
17 |
together_client = Together(
|
|
|
80 |
print( "Query: ", query)
|
81 |
|
82 |
context = get_answers( query )
|
83 |
+
|
84 |
+
sorted_answers = ['. '.join(answer['answers']) for answer in context]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
naver_end_time = time.time()
|
86 |
print(f"Time taken to extract from Naver: { naver_end_time - naver_start_time } seconds")
|
87 |
document = '\n'.join(sorted_answers)
|
|
|
108 |
response = together_client.chat.completions.create(
|
109 |
model="Qwen/Qwen2.5-7B-Instruct-Turbo",
|
110 |
messages=[
|
111 |
+
{"role": "system", "content": "You are a helpful question-answer, conversation assistant that answers in Korean. Your responses should sound human-like."},
|
112 |
{"role": "user", "content": message}
|
113 |
+
],
|
114 |
+
max_tokens = None
|
115 |
#TODO: Change the messages option
|
116 |
)
|
117 |
qwen_end_time = time.time()
|
|
|
255 |
return results
|
256 |
|
257 |
def chatFunction( message, history ):
|
258 |
+
content = f'์๋ ๋ฌธ์๋ฅผ ๋ฐํ์ผ๋ก ์ง๋ฌธ์ ๋ตํ์ธ์. ๋ต๋ณ์์ ์ง๋ฌธ์ ๋ฐ๋ผ ์ถ๋ ฅ ํ์ง ๋ง์ธ์. ๋ต๋ณ์ ํ๊ตญ์ด๋ก๋ง ํด์ฃผ์ธ์! ์ฐพ์ Naver ๋ฌธ์์ ๋ค๋ฅธ ๋ฌธ์์์ ๋ต๋ณ์ด ์๋ ๋ด์ฉ์ ์ ๋ ์ถ๋ ฅํ์ง ๋ง์ธ์. ์น์ ํ๊ณ ์ธ๊ฐ๋ต๊ฒ ๋งํ์ธ์. \n ์ง๋ฌธ: {message}\n ๋ฌธ์: '
|
259 |
naver_docs, naver_time_taken = get_naver_answers( message )
|
260 |
|
261 |
+
if len(naver_docs) > 55000:
|
262 |
+
overlap = 200
|
263 |
+
answers = []
|
264 |
+
split_len = len(naver_docs) // ( ( len(naver_docs) - 55000 ) // 55000 + 2 ) + 1
|
265 |
+
for i in range( len(naver_docs), split_len ):
|
266 |
+
if i == 0:
|
267 |
+
split = naver_docs[:split_len]
|
268 |
+
else:
|
269 |
+
split = naver_docs[i * split_len - overlap: (i + 1) * split_len]
|
270 |
+
answer, _ = get_qwen_small_answer(f"Summarize important points in a paragraph, given the information below, using only Korean language. Give me only the summary!!! \n {split}")
|
271 |
+
answers.append(answer)
|
272 |
+
naver_docs = '\n'.join(answers)
|
273 |
+
|
274 |
start_time = time.time()
|
275 |
content += "\n Naver ๋ฌธ์: " + naver_docs
|
276 |
|
|
|
|
|
277 |
completion = gpt_client.chat.completions.create(
|
278 |
model="gpt-4o-mini",
|
279 |
messages=[
|
280 |
+
{"role": "system", "content": "You are a helpful assistant that gives detailed answers only in korean."},
|
281 |
{
|
282 |
"role": "user",
|
283 |
"content": message
|