openfree commited on
Commit
1954bdb
ยท
verified ยท
1 Parent(s): bcf4357

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -34
app.py CHANGED
@@ -600,43 +600,37 @@ def generate_report(title, info, progress=gr.Progress()):
600
 
601
  progress(0.5, desc="AI ๋ชจ๋ธ ์ฒ˜๋ฆฌ ์ค‘...")
602
 
603
- try:
604
- response = hf_client.text_generation(
605
- prompt,
606
- max_new_tokens=4000,
607
- temperature=0.3,
608
- repetition_penalty=1.2
609
- )
610
-
611
- progress(0.8, desc="๊ฒฐ๊ณผ ์ฒ˜๋ฆฌ ์ค‘...")
612
-
613
- if response:
614
- formatted_response = f"""### AI ๋ฆฌํฌํŒ… ๊ฒฐ๊ณผ\n\n{response}"""
615
- return [
616
- gr.update(value=formatted_response, visible=True),
617
- gr.update(value="์ ‘๊ธฐ", visible=True)
618
- ]
619
- else:
620
- return [
621
- gr.update(value="๋ฆฌํฌํŒ… ์ƒ์„ฑ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.", visible=True),
622
- gr.update(value="์ ‘๊ธฐ", visible=True)
623
- ]
624
 
625
- except Exception as e:
626
- print(f"Model error: {str(e)}")
627
- return [
628
- gr.update(value="AI ๋ชจ๋ธ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.", visible=True),
629
- gr.update(value="์ ‘๊ธฐ", visible=True)
630
- ]
 
 
 
 
 
 
 
 
631
 
632
  except Exception as e:
633
- print(f"Report generation error: {str(e)}")
634
- return [
635
- gr.update(value="๋ฆฌํฌํŒ… ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.", visible=True),
636
- gr.update(value="์ ‘๊ธฐ", visible=True)
637
- ]
638
- finally:
639
- progress(1.0, desc="์™„๋ฃŒ!")
640
 
641
  def toggle_report(report_content, show_report):
642
  """๋ฆฌํฌํŠธ ํ‘œ์‹œ/์ˆจ๊น€ ํ† ๊ธ€"""
 
600
 
601
  progress(0.5, desc="AI ๋ชจ๋ธ ์ฒ˜๋ฆฌ ์ค‘...")
602
 
603
+ # ์ตœ๋Œ€ 3๋ฒˆ ์žฌ์‹œ๋„
604
+ max_retries = 3
605
+ for attempt in range(max_retries):
606
+ try:
607
+ response = hf_client.text_generation(
608
+ prompt,
609
+ max_new_tokens=2000, # ํ† ํฐ ์ˆ˜ ์ค„์ž„
610
+ temperature=0.7,
611
+ repetition_penalty=1.2,
612
+ return_full_text=False,
613
+ max_time=180 # ํƒ€์ž„์•„์›ƒ 180์ดˆ๋กœ ์ฆ๊ฐ€
614
+ )
 
 
 
 
 
 
 
 
 
615
 
616
+ if response:
617
+ progress(1.0, desc="์™„๋ฃŒ!")
618
+ formatted_response = f"### AI ๋ฆฌํฌํŒ…\n\n{response}"
619
+ return [formatted_response, gr.update(visible=True)]
620
+
621
+ except Exception as e:
622
+ if attempt < max_retries - 1:
623
+ print(f"Retry {attempt + 1}/{max_retries} after error: {str(e)}")
624
+ time.sleep(5) # 5์ดˆ ๋Œ€๊ธฐ ํ›„ ์žฌ์‹œ๋„
625
+ continue
626
+ else:
627
+ raise e
628
+
629
+ return ["๋ฆฌํฌํŒ… ์ƒ์„ฑ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์‹œ ์‹œ๋„ํ•ด์ฃผ์„ธ์š”.", gr.update(visible=True)]
630
 
631
  except Exception as e:
632
+ print(f"Model error: {str(e)}")
633
+ return ["AI ๋ชจ๋ธ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. ์ž ์‹œ ํ›„ ๋‹ค์‹œ ์‹œ๋„ํ•ด์ฃผ์„ธ์š”.", gr.update(visible=True)]
 
 
 
 
 
634
 
635
  def toggle_report(report_content, show_report):
636
  """๋ฆฌํฌํŠธ ํ‘œ์‹œ/์ˆจ๊น€ ํ† ๊ธ€"""