bep40 commited on
Commit
bc44def
·
verified ·
1 Parent(s): 5066b9e

Restore main.py to revision b027175

Browse files
Files changed (1) hide show
  1. main.py +9 -33
main.py CHANGED
@@ -681,42 +681,18 @@ def _article_by_url(url):
681
  if "thethaovanhoa.vn" in url:return scrape_ttvh_article(url)
682
  return None
683
 
684
- def _infer_voice_style(title, text):
685
- s=(title+' '+text).lower()
686
- if any(k in s for k in ['bóng đá','world cup','trận đấu','đội tuyển','ngoại hạng','champions','bàn thắng','hlv','cầu thủ']):
687
- return 'Giọng đọc thể thao: nhanh, hào hứng, giàu nhịp điệu, nhấn mạnh diễn biến và kết quả.'
688
- if any(k in s for k in ['ai','trí tuệ nhân tạo','công nghệ','robot','iphone','ứng dụng','dữ liệu','mạng xã hội','chip']):
689
- return 'Giọng đọc công nghệ: rõ ràng, hiện đại, giải thích dễ hiểu, nhấn mạnh điểm mới và tác động.'
690
- if any(k in s for k in ['sức khỏe','bệnh','bác sĩ','y tế','thuốc','dinh dưỡng','virus','tiêm']):
691
- return 'Giọng đọc sức khỏe: điềm tĩnh, tin cậy, dễ nghe, ưu tiên thông tin cần lưu ý.'
692
- if any(k in s for k in ['kinh tế','thị trường','giá','doanh nghiệp','chứng khoán','ngân hàng','tỷ phú']):
693
- return 'Giọng đọc kinh tế: chững chạc, mạch lạc, tập trung số liệu và ảnh hưởng thực tế.'
694
- if any(k in s for k in ['mỹ','nga','trung quốc','ukraine','israel','thế giới','châu âu','asean']):
695
- return 'Giọng đọc thời sự quốc tế: nghiêm túc, trung lập, nhấn vào bối cảnh và hệ quả.'
696
- if any(k in s for k in ['giải trí','nghệ sĩ','ca sĩ','diễn viên','hoa hậu','phim','showbiz']):
697
- return 'Giọng đọc giải trí: nhẹ nhàng, cuốn hút, giàu cảm xúc nhưng không giật gân.'
698
- return 'Giọng đọc tin nóng: ngắn gọn, rõ ý, nhấn mạnh thông tin mới nhất và điều người xem cần biết.'
699
-
700
  def _ai_rewrite_article(data):
701
- title=(data or {}).get('title','').strip()
702
- summary=(data or {}).get('summary','').strip()
703
- ps=[b.get('text','').strip() for b in (data or {}).get('body',[]) if b.get('type')=='p' and len(b.get('text','').strip())>30]
704
- source_text=' '.join([summary]+ps[:6]).strip()
705
- voice=_infer_voice_style(title, source_text)
706
- lead=summary or (ps[0] if ps else title)
707
- if len(lead)>260: lead=lead[:257]+'...'
708
  points=[]
709
  for p in ps[:5]:
710
- t=' '.join(p.split()).strip()
711
- if len(t)>170:t=t[:167]+'...'
712
- if t and t not in points:points.append(t)
713
- script=[]
714
- if title: script.append('Mở đầu: '+title)
715
- if lead: script.append('Tóm tắt: '+lead)
716
- for i,p in enumerate(points[:4],1):
717
- script.append('Ý chính %d: %s' % (i,p))
718
- script.append('Kết lại: Đây là những điểm đáng chú ý nhất. Theo dõi VNEWS để cập nhật tiếp.')
719
- return 'Bản tin AI viết lại: '+title+'\n\n'+voice+'\n\n'+'\n'.join('• '+x for x in script)
720
 
721
  @app.get("/api/wall")
722
  def api_wall():return JSONResponse({"posts":_load_wall()[:50]})
 
681
  if "thethaovanhoa.vn" in url:return scrape_ttvh_article(url)
682
  return None
683
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
684
  def _ai_rewrite_article(data):
685
+ title=(data or {}).get("title","");summary=(data or {}).get("summary","")
686
+ ps=[b.get("text","") for b in (data or {}).get("body",[]) if b.get("type")=="p" and len(b.get("text",""))>30]
687
+ lead=summary or (ps[0] if ps else "")
 
 
 
 
688
  points=[]
689
  for p in ps[:5]:
690
+ t=p.strip()
691
+ if len(t)>180:t=t[:177]+"..."
692
+ points.append(t)
693
+ rewritten="Bản tin AI viết lại: "+title+"\n\n"+lead
694
+ if points:rewritten += "\n\nĐiểm chính:\n" + "\n".join(["• "+x for x in points])
695
+ return rewritten
 
 
 
 
696
 
697
  @app.get("/api/wall")
698
  def api_wall():return JSONResponse({"posts":_load_wall()[:50]})