anisrashidov commited on
Commit
a3cd2ab
ยท
verified ยท
1 Parent(s): 3e01798

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -17
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
- answer_count = 0
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, CONCISE conversation assistant that answers in Korean."},
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 ๋ฌธ์„œ์™€ ๋‹ค๋ฅธ ๋ฌธ์„œ์—์„œ ๋‹ต๋ณ€์ด ์—†๋Š” ๋‚ด์šฉ์€ ์ ˆ๋Œ€ ์ถœ๋ ฅํ•˜์ง€ ๋งˆ์„ธ์š” \n ์งˆ๋ฌธ: {message}\n ๋ฌธ์„œ: '
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