Spaces:
Sleeping
Sleeping
File size: 3,595 Bytes
b9ecb65 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
import os
from gradio_client import Client, file
# --- ์ค์ ---
# ๋ก์ปฌ Gradio ์๋ฒ ์ฃผ์ (app.py ์คํ ์ ํฐ๋ฏธ๋์ ํ์๋๋ ์ฃผ์)
SERVER_URL = "http://localhost:8006/"
def run_chat_test(client):
"""์ผ๋ฐ ์ฑํ
ํญ์ ๊ธฐ๋ฅ์ ํ
์คํธํฉ๋๋ค."""
print("\n--- ๐ฌ ์ผ๋ฐ ์ฑํ
ํ
์คํธ ์์ ---")
test_message = "์๋
ํ์ธ์! ์ค๋ ๋ ์จ๋ ์ด๋ค๊ฐ์?"
chat_history = [] # ์ด๊ธฐ ๋ํ ๋ด์ญ์ ๋น์ด์์
print(f"๋ณด๋ด๋ ๋ฉ์์ง: '{test_message}'")
# `respond` ํจ์ ํธ์ถ (API ์๋ํฌ์ธํธ ์ธ๋ฑ์ค: 0)
# ์
๋ ฅ: (๋ฉ์์ง, ์ฑํ
๋ด์ญ, ํ์ผ)
# ์ถ๋ ฅ: (๋น์์ง ํ
์คํธ ๋ฐ์ค, ๊ฐฑ์ ๋ ์ฑํ
๋ด์ญ)
result = client.predict(
test_message,
chat_history,
None, # ํ์ผ ์์
fn_index=0
)
# ๊ฐฑ์ ๋ ์ฑํ
๋ด์ญ์์ ๋ง์ง๋ง ์๋ต(๋ด ๋ฉ์์ง)์ ์ถ์ถ
updated_history = result[1]
bot_response = updated_history[-1]['content']
print("โ
ํ
์คํธ ์ฑ๊ณต!")
print(f"๐ค ๋ฐ์ ์๋ต: '{bot_response}'")
def run_math_test(client):
"""์ํ ๋ฌธ์ ํด๊ฒฐ ํญ์ ๊ธฐ๋ฅ์ ํ
์คํธํฉ๋๋ค."""
print("\n--- ๐งฎ ์ํ ๋ฌธ์ ํด๊ฒฐ ํ
์คํธ ์์ ---")
test_problem = "๋ ๊ฐ์ ์ฐ์๋ ์ง์์ ํฉ์ด 34์ผ ๋, ๋ ์ง์๋ ๋ฌด์์ธ๊ฐ์?"
print(f"๋ณด๋ด๋ ๋ฌธ์ : '{test_problem}'")
# ์ํ ๋ฌธ์ ํด๊ฒฐ ํจ์ ํธ์ถ (API ์๋ํฌ์ธํธ ์ธ๋ฑ์ค: 1)
# ์
๋ ฅ: (์ํ ๋ฌธ์ , ํ์ผ)
# ์ถ๋ ฅ: (๊ฒฐ๊ณผ ํ
์คํธ)
result = client.predict(
test_problem,
None, # ํ์ผ ์์
fn_index=1
)
print("โ
ํ
์คํธ ์ฑ๊ณต!")
print(f"๐ค ๋ฐ์ ์๋ต (์ผ๋ถ): '{result[:200]}...'")
def run_file_test(client):
"""ํ์ผ ์
๋ก๋ ๊ธฐ๋ฅ์ ํ
์คํธํฉ๋๋ค."""
print("\n--- ๐ ํ์ผ ์
๋ก๋ ์ฑํ
ํ
์คํธ ์์ ---")
# ํ
์คํธ์ฉ ์์ ํ
์คํธ ํ์ผ ์์ฑ
temp_file_path = "test_document.txt"
with open(temp_file_path, "w", encoding="utf-8") as f:
f.write("์ด ํ์ผ์ ํ
์คํธ๋ฅผ ์ํด ์์ฑ๋์์ต๋๋ค.\n")
f.write("ํ์ผ์ ํต์ฌ ๋ด์ฉ์ '๋ํ๋ฏผ๊ตญ์ ์๋๋ ์์ธ์ด๋ค' ์
๋๋ค.")
print(f"์
๋ก๋ํ ํ์ผ: '{temp_file_path}'")
test_message = "์
๋ก๋ํ ํ์ผ์ ํต์ฌ ๋ด์ฉ์ด ๋ญ์ผ?"
print(f"๋ณด๋ด๋ ๋ฉ์์ง: '{test_message}'")
# `file()` ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ํ์ผ์ ์๋ฒ์ ์
๋ก๋ ๊ฐ๋ฅํ ํํ๋ก ๋ณํ
result = client.predict(
test_message,
[], # ์ฑํ
๋ด์ญ ์์
file(temp_file_path),
fn_index=0
)
# ์์ ํ์ผ ์ญ์
os.remove(temp_file_path)
bot_response = result[1][-1]['content']
print("โ
ํ
์คํธ ์ฑ๊ณต!")
print(f"๐ค ๋ฐ์ ์๋ต: '{bot_response}'")
if __name__ == "__main__":
print(f"Gradio ์๋ฒ({SERVER_URL})์ ์ฐ๊ฒฐ์ ์๋ํฉ๋๋ค...")
try:
# ์๋ฒ์ ํด๋ผ์ด์ธํธ๋ก ์ฐ๊ฒฐ
client = Client(SERVER_URL, verbose=False)
print("โ
์๋ฒ ์ฐ๊ฒฐ ์ฑ๊ณต!")
# ํ
์คํธ ์คํ
run_chat_test(client)
run_math_test(client)
# run_file_test(client) # ํ์ผ ํ
์คํธ๋ ํ์์ ์ฃผ์ ํด์ ํ์ฌ ์ฌ์ฉ
except Exception as e:
print(f"\nโ ํ
์คํธ ์คํจ: ์๋ฒ์ ์ฐ๊ฒฐํ ์ ์๊ฑฐ๋ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.")
print("๋จผ์ ๋ค๋ฅธ ํฐ๋ฏธ๋์์ 'python app.py'๋ฅผ ์คํํ๋์ง ํ์ธํด์ฃผ์ธ์.")
print(f"์ค๋ฅ ์์ธ ์ ๋ณด: {e}") |