Spaces:
Runtime error
Runtime error
Update app-backup.py
Browse files80 unmodified lines818283848586871 unmodified line8990919293949596979869 unmodified lines16816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221380 unmodified lines@dataclassclass ConversationConfig:max_words: int = 6000 # 4000์์ 6000์ผ๋ก ์ฆ๊ฐ (1.5๋ฐฐ)prefix_url: str = "https://r.jina.ai/"api_model_name: str = "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo"legacy_local_model_name: str = "NousResearch/Hermes-2-Pro-Llama-3-8B"1 unmodified linelocal_model_name: str = "Private-BitSix-Mistral-Small-3.1-24B-Instruct-2503.gguf"local_model_repo: str = "ginigen/Private-BitSix-Mistral-Small-3.1-24B-Instruct-2503"# ํ ํฐ ์ ์ฆ๊ฐmax_tokens: int = 4500 # 3000์์ 4500์ผ๋ก ์ฆ๊ฐ (1.5๋ฐฐ)max_new_tokens: int = 9000 # 6000์์ 9000์ผ๋ก ์ฆ๊ฐ (1.5๋ฐฐ)min_conversation_turns: int = 12 # ์ต์ ๋ํ ํด ์max_conversation_turns: int = 15 # ์ต๋ ๋ํ ํด ์def brave_search(query: str, count: int = 8, freshness_days: int | None = None):69 unmodified linesreturn []def search_and_compile_content(keyword: str, language: str = "English") -> str:"""ํค์๋๋ก ๊ฒ์ํ์ฌ ์ฝํ ์ธ ์ปดํ์ผ"""if not BRAVE_KEY:return f"Search API not available. Using keyword: {keyword}"# ์ธ์ด์ ๋ฐ๋ฅธ ๊ฒ์ ์ฟผ๋ฆฌ ์กฐ์ if language == "Korean":queries = [f"{keyword} ์ต์ ๋ด์ค",f"{keyword} ์ ๋ณด",f"{keyword} ํธ๋ ๋ 2024"]else:queries = [f"{keyword} latest news",f"{keyword} explained",f"{keyword} trends 2024"]all_content = []for query in queries:results = brave_search(query, count=3)for r in results[:2]: # ๊ฐ ์ฟผ๋ฆฌ๋น ์์ 2๊ฐ ๊ฒฐ๊ณผcontent = f"**{r['title']}**\n{r['snippet']}\n"all_content.append(content)if not all_content:return f"No search results found for: {keyword}"# ์ปดํ์ผ๋ ์ฝํ ์ธ ๋ฐํcompiled = "\n\n".join(all_content)# ํค์๋ ๊ธฐ๋ฐ ์๊ฐ ์ถ๊ฐif language == "Korean":intro = f"'{keyword}'์ ๋ํ ์ต์ ์ ๋ณด์ ํธ๋ ๋:\n\n"else:intro = f"Latest information and trends about '{keyword}':\n\n"return intro + compiledclass UnifiedAudioConverter:def __init__(self, config: ConversationConfig):self.config = config80 unmodified lines818283848586871 unmodified line8990919293949596979869 unmodified lines16816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640780 unmodified lines@dataclassclass ConversationConfig:max_words: int = 8000 # 4000์์ 6000์ผ๋ก ์ฆ๊ฐ (1.5๋ฐฐ)prefix_url: str = "https://r.jina.ai/"api_model_name: str = "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo"legacy_local_model_name: str = "NousResearch/Hermes-2-Pro-Llama-3-8B"1 unmodified linelocal_model_name: str = "Private-BitSix-Mistral-Small-3.1-24B-Instruct-2503.gguf"local_model_repo: str = "ginigen/Private-BitSix-Mistral-Small-3.1-24B-Instruct-2503"# ํ ํฐ ์ ์ฆ๊ฐmax_tokens: int = 6000 # 3000์์ 4500์ผ๋ก ์ฆ๊ฐ (1.5๋ฐฐ)max_new_tokens: int = 12000 # 6000์์ 9000์ผ๋ก ์ฆ๊ฐ (1.5๋ฐฐ)min_conversation_turns: int = 18 # ์ต์ ๋ํ ํด ์max_conversation_turns: int = 20 # ์ต๋ ๋ํ ํด ์def brave_search(query: str, count: int = 8, freshness_days: int | None = None):69 unmodified linesreturn []def search_and_compile_content(keyword: str, language: str = "English") -> str:"""ํค์๋๋ก ๊ฒ์ํ์ฌ ์ถฉ๋ถํ ์ฝํ ์ธ ์ปดํ์ผ"""if not BRAVE_KEY:# API ์์ ๋๋ ๊ธฐ๋ณธ ์ฝํ ์ธ ์์ฑif language == "Korean":return f"""'{keyword}'์ ๋ํ ์ข ํฉ์ ์ธ ์ ๋ณด:{keyword}๋ ํ๋ ์ฌํ์์ ๋งค์ฐ ์ค์ํ ์ฃผ์ ์ ๋๋ค.์ด ์ฃผ์ ๋ ๋ค์ํ ์ธก๋ฉด์์ ์ฐ๋ฆฌ์ ์ถ์ ์ํฅ์ ๋ฏธ์น๊ณ ์์ผ๋ฉฐ,์ต๊ทผ ๋ค์ด ๋์ฑ ์ฃผ๋ชฉ๋ฐ๊ณ ์์ต๋๋ค.์ฃผ์ ํน์ง:1. ๊ธฐ์ ์ ๋ฐ์ ๊ณผ ํ์2. ์ฌํ์ ์ํฅ๊ณผ ๋ณํ3. ๋ฏธ๋ ์ ๋ง๊ณผ ๊ฐ๋ฅ์ฑ4. ์ค์ฉ์ ํ์ฉ ๋ฐฉ์5. ๊ธ๋ก๋ฒ ํธ๋ ๋์ ๋ํฅ์ ๋ฌธ๊ฐ๋ค์ {keyword}๊ฐ ์์ผ๋ก ๋์ฑ ์ค์ํด์ง ๊ฒ์ผ๋ก ์์ํ๊ณ ์์ผ๋ฉฐ,์ด์ ๋ํ ๊น์ด ์๋ ์ดํด๊ฐ ํ์ํ ์์ ์ ๋๋ค."""else:return f"""Comprehensive information about '{keyword}':{keyword} is a significant topic in modern society.This subject impacts our lives in various ways and has beengaining increasing attention recently.Key aspects:1. Technological advancement and innovation2. Social impact and changes3. Future prospects and possibilities4. Practical applications5. Global trends and developmentsExperts predict that {keyword} will become even more important,and it's crucial to develop a deep understanding of this topic."""# ์ธ์ด์ ๋ฐ๋ฅธ ๋ค์ํ ๊ฒ์ ์ฟผ๋ฆฌif language == "Korean":queries = [f"{keyword} ์ต์ ๋ด์ค 2024",f"{keyword} ์ ๋ณด ์ค๋ช ",f"{keyword} ํธ๋ ๋ ์ ๋ง",f"{keyword} ์ฅ์ ๋จ์ ",f"{keyword} ํ์ฉ ๋ฐฉ๋ฒ",f"{keyword} ์ ๋ฌธ๊ฐ ์๊ฒฌ"]else:queries = [f"{keyword} latest news 2024",f"{keyword} explained comprehensive",f"{keyword} trends forecast",f"{keyword} advantages disadvantages",f"{keyword} how to use",f"{keyword} expert opinions"]all_content = []total_content_length = 0for query in queries:results = brave_search(query, count=5) # ๋ ๋ง์ ๊ฒฐ๊ณผ ๊ฐ์ ธ์ค๊ธฐfor r in results[:3]: # ๊ฐ ์ฟผ๋ฆฌ๋น ์์ 3๊ฐcontent = f"**{r['title']}**\n{r['snippet']}\nSource: {r['host']}\n"all_content.append(content)total_content_length += len(r['snippet'])# ์ฝํ ์ธ ๊ฐ ๋ถ์กฑํ๋ฉด ์ถ๊ฐ ์์ฑif total_content_length < 1000: # ์ต์ 1000์ ํ๋ณดif language == "Korean":additional_content = f"""์ถ๊ฐ ์ ๋ณด:{keyword}์ ๊ด๋ จ๋ ์ต๊ทผ ๋ํฅ์ ์ดํด๋ณด๋ฉด, ์ด ๋ถ์ผ๋ ๋น ๋ฅด๊ฒ ๋ฐ์ ํ๊ณ ์์ต๋๋ค.๋ง์ ์ ๋ฌธ๊ฐ๋ค์ด ์ด ์ฃผ์ ์ ๋ํด ํ๋ฐํ ์ฐ๊ตฌํ๊ณ ์์ผ๋ฉฐ,์ค์ํ์์์ ์์ฉ ๊ฐ๋ฅ์ฑ๋ ๊ณ์ ํ๋๋๊ณ ์์ต๋๋ค.๏ฟฝ๏ฟฝ๏ฟฝํ ์ฃผ๋ชฉํ ์ ์:- ๊ธฐ์ ํ์ ์ ๊ฐ์ํ- ์ฌ์ฉ์ ๊ฒฝํ์ ๊ฐ์- ์ ๊ทผ์ฑ์ ํฅ์- ๋น์ฉ ํจ์จ์ฑ ์ฆ๋- ๊ธ๋ก๋ฒ ์์ฅ์ ์ฑ์ฅ์ด๋ฌํ ์์๋ค์ด {keyword}์ ๋ฏธ๋๋ฅผ ๋์ฑ ๋ฐ๊ฒ ๋ง๋ค๊ณ ์์ต๋๋ค."""else:additional_content = f"""Additional insights:Recent developments in {keyword} show rapid advancement in this field.Many experts are actively researching this topic, and its practicalapplications continue to expand.Key points to note:- Accelerating technological innovation- Improving user experience- Enhanced accessibility- Increased cost efficiency- Growing global marketThese factors are making the future of {keyword} increasingly promising."""all_content.append(additional_content)# ์ปดํ์ผ๋ ์ฝํ ์ธ ๋ฐํcompiled = "\n\n".join(all_content)# ํค์๋ ๊ธฐ๋ฐ ์๊ฐif language == "Korean":intro = f"### '{keyword}'์ ๋ํ ์ข ํฉ์ ์ธ ์ ๋ณด์ ์ต์ ๋ํฅ:\n\n"else:intro = f"### Comprehensive information and latest trends about '{keyword}':\n\n"return intro + compileddef _build_prompt(self, text: str, language: str = "English", search_context: str = "") -> str:"""Build prompt for conversation generation with enhanced radio talk show style"""# ํ ์คํธ ๊ธธ์ด ์ ํmax_text_length = 4500 if search_context else 6000if len(text) > max_text_length:text = text[:max_text_length] + "..."if language == "Korean":# ๋ํ ํ ํ๋ฆฟ์ ๋ ๋ง์ ํด์ผ๋ก ํ์ฅ (15-20ํ)template = """{"conversation": [{"speaker": "์ค์", "text": ""},{"speaker": "๋ฏผํธ", "text": ""},{"speaker": "์ค์", "text": ""},{"speaker": "๋ฏผํธ", "text": ""},{"speaker": "์ค์", "text": ""},{"speaker": "๋ฏผํธ", "text": ""},{"speaker": "์ค์", "text": ""},{"speaker": "๋ฏผํธ", "text": ""},{"speaker": "์ค์", "text": ""},{"speaker": "๋ฏผํธ", "text": ""},{"speaker": "์ค์", "text": ""},{"speaker": "๋ฏผํธ", "text": ""},{"speaker": "์ค์", "text": ""},{"speaker": "๋ฏผํธ", "text": ""},{"speaker": "์ค์", "text": ""},{"speaker": "๋ฏผํธ", "text": ""},{"speaker": "์ค์", "text": ""},{"speaker": "๋ฏผํธ", "text": ""}]}"""context_part = ""if search_context:context_part = f"# ์ต์ ๊ด๋ จ ์ ๋ณด:\n{search_context}\n"base_prompt = (f"# ์๋ณธ ์ฝํ ์ธ :\n{text}\n\n"f"{context_part}"f"์ ๋ด์ฉ์ผ๋ก 30์ค ์ด์์ ๋ผ๋์ค ๋๋ด ํ๋ก๊ทธ๋จ ๋๋ณธ์ ์์ฑํด์ฃผ์ธ์.\n\n"f"## ํ์ ์๊ตฌ์ฌํญ:\n"f"1. **์ต์ 18ํ ์ด์์ ๋ํ ๊ตํ** (์ค์ 9ํ, ๋ฏผํธ 9ํ ์ด์)\n"f"2. **๋ํ ์คํ์ผ**: ์ค์ ๋ผ๋์ค ๋๋ด์ฒ๋ผ ์์ฃผ ์์ฐ์ค๋ฝ๊ณ ํธ์ํ ๊ตฌ์ด์ฒด\n"f"3. **ํ์ ์ญํ **:\n"f" - ์ค์: ์งํ์ (์งง์ ์ง๋ฌธ, ๋ฆฌ์ก์ , ํ์ ์ ํ)\n"f" - ๋ฏผํธ: ์ ๋ฌธ๊ฐ (๊ฐ๊ฒฐํ ์ค๋ช , ์์ ์ ๊ณต)\n"f"4. **๋ํ ํจํด**:\n"f" - ์ค์: \"๊ทธ๋ ๊ตฐ์\", \"ํฅ๋ฏธ๋กญ๋ค์\", \"๋ ์์ธํ ์ค๋ช ํด์ฃผ์๊ฒ ์ด์?\"\n"f" - ๋ฏผํธ: 1-2๋ฌธ์ฅ์ผ๋ก ํต์ฌ ์ค๋ช \n"f" - ์์ฐ์ค๋ฌ์ด ์ถ์์ ์ฌ์ฉ\n"f"5. **๋ด์ฉ ๊ตฌ์ฑ**:\n"f" - ๋์ ๋ถ (2-3ํ): ์ฃผ์ ์๊ฐ\n"f" - ์ ๊ฐ๋ถ (10-12ํ): ํต์ฌ ๋ด์ฉ ์ค๋ช \n"f" - ๋ง๋ฌด๋ฆฌ (3-4ํ): ์์ฝ ๋ฐ ์ ๋ฆฌ\n"f"6. **ํ์**: ์๋ก ์กด๋๋ง ์ฌ์ฉ\n\n"f"๋ฐ๋์ ์ JSON ํ์์ผ๋ก 18ํ ์ด์์ ๋ํ๋ฅผ ์์ฑํ์ธ์:\n{template}")return base_promptelse:# ์์ด ํ ํ๋ฆฟ๋ ํ์ฅtemplate = """{"conversation": [{"speaker": "Alex", "text": ""},{"speaker": "Jordan", "text": ""},{"speaker": "Alex", "text": ""},{"speaker": "Jordan", "text": ""},{"speaker": "Alex", "text": ""},{"speaker": "Jordan", "text": ""},{"speaker": "Alex", "text": ""},{"speaker": "Jordan", "text": ""},{"speaker": "Alex", "text": ""},{"speaker": "Jordan", "text": ""},{"speaker": "Alex", "text": ""},{"speaker": "Jordan", "text": ""},{"speaker": "Alex", "text": ""},{"speaker": "Jordan", "text": ""},{"speaker": "Alex", "text": ""},{"speaker": "Jordan", "text": ""},{"speaker": "Alex", "text": ""},{"speaker": "Jordan", "text": ""}]}"""context_part = ""if search_context:context_part = f"# Latest Information:\n{search_context}\n"base_prompt = (f"# Content:\n{text}\n\n"f"{context_part}"f"Create a radio talk show conversation with at least 30 lines.\n\n"f"## Requirements:\n"f"1. **Minimum 18 conversation exchanges** (Alex 9+, Jordan 9+)\n"f"2. **Style**: Natural radio talk show conversation\n"f"3. **Roles**:\n"f" - Alex: Host (short questions, reactions, transitions)\n"f" - Jordan: Expert (concise explanations, examples)\n"f"4. **Pattern**:\n"f" - Alex: \"I see\", \"Fascinating\", \"Could you elaborate?\"\n"f" - Jordan: 1-2 sentence explanations\n"f" - Natural speech fillers\n"f"5. **Structure**:\n"f" - Introduction (2-3 exchanges): Topic intro\n"f" - Main content (10-12 exchanges): Core discussion\n"f" - Conclusion (3-4 exchanges): Summary\n\n"f"Create exactly 18+ exchanges in this JSON format:\n{template}")return base_promptclass UnifiedAudioConverter:def __init__(self, config: ConversationConfig):self.config = config
app-backup.py+216-22