Spaces:
Sleeping
Sleeping
๐จ ์์ฑ: ์ด๋ฏธ์ง ํน์ฑ ๋ฐ์ AI ๊ตฌ์ฒดํ ์์คํ - ๊ธฐ๋ณธ ํจ์ + AI ์์ธํ 2๋จ๊ณ ๊ตฌ์กฐ ๊ตฌํ, ์ฌ๋ฌผ๋ณ ๊ณ ์ ํน์ฑ๊ณผ ์ฑ๊ฒฉ ์กฐํฉ์ผ๋ก ํ์ค์ ๊ฒฐํจ ์์ฑ
Browse files- app.py +114 -0
- app_backup.py +0 -0
app.py
CHANGED
@@ -2359,6 +2359,120 @@ def get_object_specific_concerns(object_type, material, purpose):
|
|
2359 |
|
2360 |
return concerns
|
2361 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2362 |
if __name__ == "__main__":
|
2363 |
app = create_main_interface()
|
2364 |
app.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
2359 |
|
2360 |
return concerns
|
2361 |
|
2362 |
+
def refine_flaws_with_ai_and_image_analysis(basic_flaws, basic_contradictions, image_analysis, personality_traits):
|
2363 |
+
"""AI๋ฅผ ํ์ฉํ์ฌ ์ด๋ฏธ์ง ๋ถ์ ๊ฒฐ๊ณผ์ ๋ง๊ฒ ๊ฒฐํจ๊ณผ ๋ชจ์์ ๊ตฌ์ฒดํ"""
|
2364 |
+
global persona_generator
|
2365 |
+
|
2366 |
+
if not persona_generator or not hasattr(persona_generator, 'api_key') or not persona_generator.api_key:
|
2367 |
+
print("โ ๏ธ API ํค ์์ - ๊ธฐ๋ณธ ๊ฒฐํจ ๊ทธ๋๋ก ์ฌ์ฉ")
|
2368 |
+
return basic_flaws, basic_contradictions
|
2369 |
+
|
2370 |
+
try:
|
2371 |
+
# ์ด๋ฏธ์ง ๋ถ์์์ ๊ตฌ์ฒด์ ํน์ฑ ์ถ์ถ
|
2372 |
+
object_type = image_analysis.get("object_type", "์ฌ๋ฌผ")
|
2373 |
+
distinctive_features = image_analysis.get("distinctive_features", [])
|
2374 |
+
shape = image_analysis.get("shape", "์ผ๋ฐ์ ์ธ ํํ")
|
2375 |
+
size = image_analysis.get("size", "๋ณดํต ํฌ๊ธฐ")
|
2376 |
+
materials = image_analysis.get("materials", ["์ ์ ์๋ ์ฌ์ง"])
|
2377 |
+
colors = image_analysis.get("colors", ["ํ์"])
|
2378 |
+
condition = image_analysis.get("condition", "๋ณดํต")
|
2379 |
+
|
2380 |
+
# ์ฑ๊ฒฉ ํน์ฑ ์์ฝ
|
2381 |
+
warmth = personality_traits.get("์จ๊ธฐ", 50)
|
2382 |
+
competence = personality_traits.get("๋ฅ๋ ฅ", 50)
|
2383 |
+
extraversion = personality_traits.get("์ธํฅ์ฑ", 50)
|
2384 |
+
|
2385 |
+
# AI ํ๋กฌํํธ ์์ฑ
|
2386 |
+
ai_prompt = f"""
|
2387 |
+
๋ค์ ๊ธฐ๋ณธ ๋งค๋ ฅ์ ๊ฒฐํจ๋ค์ ์ค์ ์ด๋ฏธ์ง ๋ถ์ ๊ฒฐ๊ณผ์ ๋ง๊ฒ ๊ตฌ์ฒดํํด์ฃผ์ธ์.
|
2388 |
+
|
2389 |
+
**์ค์ ์ด๋ฏธ์ง ๋ถ์ ๊ฒฐ๊ณผ:**
|
2390 |
+
- ์ฌ๋ฌผ: {object_type}
|
2391 |
+
- ํน์ง์ ์์: {', '.join(distinctive_features)}
|
2392 |
+
- ํํ: {shape}
|
2393 |
+
- ํฌ๊ธฐ: {size}
|
2394 |
+
- ์ฌ์ง: {', '.join(materials)}
|
2395 |
+
- ์์: {', '.join(colors)}
|
2396 |
+
- ์ํ: {condition}
|
2397 |
+
|
2398 |
+
**์ฑ๊ฒฉ ํน์ฑ:**
|
2399 |
+
- ์จ๊ธฐ: {warmth}/100
|
2400 |
+
- ๋ฅ๋ ฅ: {competence}/100
|
2401 |
+
- ์ธํฅ์ฑ: {extraversion}/100
|
2402 |
+
|
2403 |
+
**๊ธฐ๋ณธ ๊ฒฐํจ๋ค (์์ ํ์):**
|
2404 |
+
{chr(10).join([f"{i+1}. {flaw}" for i, flaw in enumerate(basic_flaws)])}
|
2405 |
+
|
2406 |
+
**์์ฒญ์ฌํญ:**
|
2407 |
+
1. ์ค์ ์ด๋ฏธ์ง์ ์๋ ํน์ฑ(์: ์์ก์ด ์๋๋ฐ ์์ก์ด ๊ฑฑ์ )์ ์ ๊ฑฐํ๊ณ ์ค์ ํน์ฑ์ผ๋ก ๋์ฒด
|
2408 |
+
2. ๊ตฌ์ฒด์ ์ธ ์ฌ์ง, ์์, ํฌ๊ธฐ, ํํ๋ฅผ ๋ฐ์ํ ๊ฑฑ์ ๊ฑฐ๋ฆฌ๋ก ๋ณ๊ฒฝ
|
2409 |
+
3. ํน์ง์ ์์๋ค์ ํ์ฉํ ๊ฐ์ฑ ์๋ ๊ฒฐํจ์ผ๋ก ์
๊ทธ๋ ์ด๋
|
2410 |
+
4. ๊ฐ ๊ฒฐํจ์ 15-30์ ๋ด์ธ๋ก ๊ตฌ์ฒด์ ์ด๊ณ ๋งค๋ ฅ์ ์ผ๋ก
|
2411 |
+
|
2412 |
+
**์์:**
|
2413 |
+
- "์์ก์ด๊ฐ ํธํ์ง ์ ๊ฒฝ ์ฐ์" โ (์์ก์ด ์์ผ๋ฉด) "๋ฅ๊ทผ ๋ชจ์์ด๋ผ ๋ฏธ๋๋ฌ์ ธ ๋จ์ด์ง๊น ๋ด ๊ฑฑ์ "
|
2414 |
+
- "์์ด ๋ฐ๋๊น ๊ฑฑ์ " โ "ํ๋์์ด ๋๋ฌด ์ ๋ช
ํด์ ํ์ด ๋ณด์ผ๊น ๊ฑฑ์ "
|
2415 |
+
|
2416 |
+
๊ฐ์ ๋ ๋งค๋ ฅ์ ๊ฒฐํจ 4๊ฐ๋ฅผ ๋ฒํธ ์์ด ์ค๋ฐ๊ฟ์ผ๋ก ๊ตฌ๋ถํ์ฌ ์์ฑ:
|
2417 |
+
"""
|
2418 |
+
|
2419 |
+
# AI๋ก ๊ฒฐํจ ๊ตฌ์ฒดํ
|
2420 |
+
refined_flaws_text = persona_generator._generate_text_with_api(ai_prompt)
|
2421 |
+
|
2422 |
+
if refined_flaws_text and len(refined_flaws_text.strip()) > 20:
|
2423 |
+
refined_flaws = []
|
2424 |
+
lines = refined_flaws_text.strip().split('\n')
|
2425 |
+
for line in lines:
|
2426 |
+
cleaned_line = line.strip().lstrip('1234567890.-โข ')
|
2427 |
+
if cleaned_line and len(cleaned_line) > 5:
|
2428 |
+
refined_flaws.append(cleaned_line)
|
2429 |
+
|
2430 |
+
if len(refined_flaws) >= 4:
|
2431 |
+
final_flaws = refined_flaws[:4]
|
2432 |
+
else:
|
2433 |
+
# ๋ถ์กฑํ๋ฉด ๊ธฐ๋ณธ ๊ฒฐํจ์ผ๋ก ์ฑ์ฐ๊ธฐ
|
2434 |
+
final_flaws = refined_flaws + basic_flaws[len(refined_flaws):4]
|
2435 |
+
else:
|
2436 |
+
final_flaws = basic_flaws
|
2437 |
+
|
2438 |
+
# ๋ชจ์์ ํน์ฑ๋ ๊ฐ์ ๋ฐฉ์์ผ๋ก ๊ตฌ์ฒดํ
|
2439 |
+
contradiction_prompt = f"""
|
2440 |
+
๋ค์ ๊ธฐ๋ณธ ๋ชจ์์ ํน์ฑ๋ค์ ์ค์ ์ด๋ฏธ์ง ํน์ฑ์ ๋ง๊ฒ ๊ตฌ์ฒดํํด์ฃผ์ธ์.
|
2441 |
+
|
2442 |
+
**์ค์ ์ด๋ฏธ์ง:**
|
2443 |
+
{object_type} - {shape}, {size}, {', '.join(materials)}, {', '.join(colors)}
|
2444 |
+
ํน์ง: {', '.join(distinctive_features)}
|
2445 |
+
|
2446 |
+
**๊ธฐ๋ณธ ๋ชจ์๋ค:**
|
2447 |
+
{chr(10).join([f"{i+1}. {cont}" for i, cont in enumerate(basic_contradictions)])}
|
2448 |
+
|
2449 |
+
์ค์ ํน์ฑ์ ๋ฐ์ํ ๊ตฌ์ฒด์ ์ธ ๋ชจ์ 2๊ฐ๋ฅผ ์์ฑ:
|
2450 |
+
"""
|
2451 |
+
|
2452 |
+
refined_contradictions_text = persona_generator._generate_text_with_api(contradiction_prompt)
|
2453 |
+
|
2454 |
+
if refined_contradictions_text and len(refined_contradictions_text.strip()) > 20:
|
2455 |
+
refined_contradictions = []
|
2456 |
+
lines = refined_contradictions_text.strip().split('\n')
|
2457 |
+
for line in lines:
|
2458 |
+
cleaned_line = line.strip().lstrip('1234567890.-โข ')
|
2459 |
+
if cleaned_line and len(cleaned_line) > 5:
|
2460 |
+
refined_contradictions.append(cleaned_line)
|
2461 |
+
|
2462 |
+
if len(refined_contradictions) >= 2:
|
2463 |
+
final_contradictions = refined_contradictions[:2]
|
2464 |
+
else:
|
2465 |
+
final_contradictions = refined_contradictions + basic_contradictions[len(refined_contradictions):2]
|
2466 |
+
else:
|
2467 |
+
final_contradictions = basic_contradictions
|
2468 |
+
|
2469 |
+
print(f"๐จ AI๊ฐ ์ด๋ฏธ์ง ํน์ฑ ๋ฐ์ํ์ฌ ๊ฒฐํจ/๋ชจ์ ๊ตฌ์ฒดํ ์๋ฃ")
|
2470 |
+
return final_flaws, final_contradictions
|
2471 |
+
|
2472 |
+
except Exception as e:
|
2473 |
+
print(f"โ ๏ธ AI ๊ตฌ์ฒดํ ์คํจ: {e} - ๊ธฐ๋ณธ ๊ฒฐํจ ์ฌ์ฉ")
|
2474 |
+
return basic_flaws, basic_contradictions
|
2475 |
+
|
2476 |
if __name__ == "__main__":
|
2477 |
app = create_main_interface()
|
2478 |
app.launch(server_name="0.0.0.0", server_port=7860)
|
app_backup.py
CHANGED
The diff for this file is too large to render.
See raw diff
|
|