Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/1234567890244_2025-automatic-meme-generation-with-text-based-on-facial-expressions.json
T

1 line
8.2 KiB
JSON

{"repo": "1234567890244/2025-automatic-meme-generation-with-text-based-on-facial-expressions", "files": {"core/text_generator.py": {"8a536ba490b1ddf87f23d3161829fbd64e528d49": {"t": 1785746405.5293245, "n": 3093, "h": "e34fac4d9e552715", "c": "from openai import OpenAI\nimport requests\n\n\nclass EmotionFusionGenerator:\n def __init__(self, llm_model=\"deepseek-chat\"):\n self.api_key = 'sk-62167b879ab04cac9b75e04401351095'\n self.llm_model = llm_model\n self.emotion_labels = ['angry', 'disgust', 'fear', 'happy', 'sad', 'surprise', 'neutral']\n\n self.client = OpenAI(\n api_key=self.api_key,\n base_url=\"https://api.deepseek.com/v1\"\n ) if self.api_key else None\n\n @staticmethod\n def check_api_key(api_key):\n url = \"https://api.deepseek.com/v1/models\"\n headers = {\"Authorization\": f\"Bearer {api_key}\"}\n try:\n response = requests.get(url, headers=headers)\n print(f\"API Key Status: {response.status_code}\")\n if response.status_code == 200:\n print(\"API Key Valid\")\n return True\n print(f\"Response: {response.json()}\")\n return False\n except Exception as e:\n print(f\"Fail in examination: {str(e)}\")\n return False\n\n def generate_prompt(self, emotions, percentages, context=None):\n emotion_desc = []\n for emo, pct in zip(emotions, percentages):\n emotion_desc.append(f\"{emo}({pct:.1%})\")\n print(emotion_desc)\n\n prompt = (\n \"你是一个专业的情绪分析文案生成器。根据以下情绪分布,找到最能够描述这种复杂情绪的语句,创作一句简洁的表情包文案:\\n\"\n f\"情绪分布: {', '.join(emotion_desc)}\\n\\n\"\n \"要求:\\n\"\n \"1. 使用生动形象的感官描写\\n\"\n \"2. 反映情绪之间的微妙平衡\\n\"\n \"3. 字数在1-5字之间\\n\"\n \"4. 输出的文本不要用双引号包裹\\n\"\n \"5. 避免重复描述\\n\"\n \"6. 确保输出的文案没有错误\\n\"\n \"7. 确保输出的语言浅显易懂经典自然\\n\"\n \"8. 避免直接把表达不同情绪的词语连接在一起\\n\"\n \"9. 可以适当融入网络热梗\\n\"\n \"10. 降低占比远低于其他情绪的情绪对文案的影响\\n\"\n \"11. 除非'neutral'情绪占比远高于其他情绪,否则将除'neutral'情绪外的、占比最大的情绪视为主要情绪,'neutral'占比只影响该情绪强烈程度\\n\"\n \"例子:\\n\"\n \"['happy(90.1%)', 'neutral(9.9%)']输出'哈哈哈哈哈'\\n\"\n \"解释:这个例子中'happy'占比远高于'neutral',因此生成的文案更偏向'happy'情绪\\n\"\n \"['happy(50.1%)', 'neutral(49.9%)']输出'礼貌性微笑'\\n\"\n \"解释:这个例子中'happy'占比与'neutral'相近,因此生成的文案以'happy'作为主要情绪,'neutral'占比较高代表'happy'情绪不是非常强烈,因此输出文案比较平静\\n\"\n )\n\n if context:\n prompt += f\"\\nExtra context: {context}\\n\"\n\n return prompt\n\n def generate_caption(self, emotions, percentages, context=None):\n if not self.client:\n return \"LLM API key not provided or invalid\"\n\n prompt = self.generate_prompt(emotions, percentages, context)\n\n try:\n response = self.client.chat.completions.create(\n model=self.llm_model,\n messages=[\n {\"role\": \"system\",\n \"content\": \"你是一个熟悉网络用语的文案作家,擅长为表情包撰写前沿潮流、生动有趣的文案。\"},\n {\"role\": \"user\", \"content\": prompt}\n ],\n temperature=0.7,\n max_tokens=10\n )\n return response.choices[0].message.content.strip()\n except Exception as e:\n print(f\"Error in LLM generation: {str(e)}\")\n return\n"}, "c59854196a84652d521e226f45ea14f6e1854aba": {"t": 1785763570.1832125, "n": 3093, "h": "e34fac4d9e552715", "c": "from openai import OpenAI\nimport requests\n\n\nclass EmotionFusionGenerator:\n def __init__(self, llm_model=\"deepseek-chat\"):\n self.api_key = 'sk-62167b879ab04cac9b75e04401351095'\n self.llm_model = llm_model\n self.emotion_labels = ['angry', 'disgust', 'fear', 'happy', 'sad', 'surprise', 'neutral']\n\n self.client = OpenAI(\n api_key=self.api_key,\n base_url=\"https://api.deepseek.com/v1\"\n ) if self.api_key else None\n\n @staticmethod\n def check_api_key(api_key):\n url = \"https://api.deepseek.com/v1/models\"\n headers = {\"Authorization\": f\"Bearer {api_key}\"}\n try:\n response = requests.get(url, headers=headers)\n print(f\"API Key Status: {response.status_code}\")\n if response.status_code == 200:\n print(\"API Key Valid\")\n return True\n print(f\"Response: {response.json()}\")\n return False\n except Exception as e:\n print(f\"Fail in examination: {str(e)}\")\n return False\n\n def generate_prompt(self, emotions, percentages, context=None):\n emotion_desc = []\n for emo, pct in zip(emotions, percentages):\n emotion_desc.append(f\"{emo}({pct:.1%})\")\n print(emotion_desc)\n\n prompt = (\n \"你是一个专业的情绪分析文案生成器。根据以下情绪分布,找到最能够描述这种复杂情绪的语句,创作一句简洁的表情包文案:\\n\"\n f\"情绪分布: {', '.join(emotion_desc)}\\n\\n\"\n \"要求:\\n\"\n \"1. 使用生动形象的感官描写\\n\"\n \"2. 反映情绪之间的微妙平衡\\n\"\n \"3. 字数在1-5字之间\\n\"\n \"4. 输出的文本不要用双引号包裹\\n\"\n \"5. 避免重复描述\\n\"\n \"6. 确保输出的文案没有错误\\n\"\n \"7. 确保输出的语言浅显易懂经典自然\\n\"\n \"8. 避免直接把表达不同情绪的词语连接在一起\\n\"\n \"9. 可以适当融入网络热梗\\n\"\n \"10. 降低占比远低于其他情绪的情绪对文案的影响\\n\"\n \"11. 除非'neutral'情绪占比远高于其他情绪,否则将除'neutral'情绪外的、占比最大的情绪视为主要情绪,'neutral'占比只影响该情绪强烈程度\\n\"\n \"例子:\\n\"\n \"['happy(90.1%)', 'neutral(9.9%)']输出'哈哈哈哈哈'\\n\"\n \"解释:这个例子中'happy'占比远高于'neutral',因此生成的文案更偏向'happy'情绪\\n\"\n \"['happy(50.1%)', 'neutral(49.9%)']输出'礼貌性微笑'\\n\"\n \"解释:这个例子中'happy'占比与'neutral'相近,因此生成的文案以'happy'作为主要情绪,'neutral'占比较高代表'happy'情绪不是非常强烈,因此输出文案比较平静\\n\"\n )\n\n if context:\n prompt += f\"\\nExtra context: {context}\\n\"\n\n return prompt\n\n def generate_caption(self, emotions, percentages, context=None):\n if not self.client:\n return \"LLM API key not provided or invalid\"\n\n prompt = self.generate_prompt(emotions, percentages, context)\n\n try:\n response = self.client.chat.completions.create(\n model=self.llm_model,\n messages=[\n {\"role\": \"system\",\n \"content\": \"你是一个熟悉网络用语的文案作家,擅长为表情包撰写前沿潮流、生动有趣的文案。\"},\n {\"role\": \"user\", \"content\": prompt}\n ],\n temperature=0.7,\n max_tokens=10\n )\n return response.choices[0].message.content.strip()\n except Exception as e:\n print(f\"Error in LLM generation: {str(e)}\")\n return\n"}}}}