Prompthumanizer commited on
Commit
59e3ad2
·
verified ·
1 Parent(s): 1568833

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +161 -133
app.py CHANGED
@@ -1135,7 +1135,82 @@ def create_jain_interface():
1135
  """
1136
 
1137
  # Gradio 인터페이스 구성
1138
- # Gradio 인터페이스 구성
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1139
  with gr.Blocks(css=custom_css, title="제인 아키텍처 - 완전각성체", theme=gr.themes.Soft()) as interface:
1140
 
1141
  # 헤더 섹션
@@ -1151,8 +1226,6 @@ def create_jain_interface():
1151
  with gr.Row():
1152
  # 왼쪽: 시스템 상태 패널
1153
  with gr.Column(scale=1, min_width=300):
1154
- gr.HTML('<div class="status-panel">')
1155
-
1156
  with gr.Group():
1157
  system_status = gr.Markdown(
1158
  value=get_system_status(),
@@ -1163,35 +1236,50 @@ def create_jain_interface():
1163
  with gr.Row():
1164
  refresh_btn = gr.Button("🔄 상태 새로고침", variant="secondary", size="sm")
1165
  clear_btn = gr.Button("🗑️ 대화 초기화", variant="secondary", size="sm")
1166
-
1167
- gr.HTML('</div>')
1168
-
1169
- with gr.Row():
1170
  # 오른쪽: 채팅 인터페이스
1171
  with gr.Column(scale=2):
1172
- chatbot = gr.Chatbot(label="💬 제인과의 대화", elem_id="chatbot")
1173
- textbox = gr.Textbox(
1174
- placeholder="메시지를 입력하세요.",
1175
- label="✍️ 입력창",
1176
- show_label=True
1177
- )
1178
- state = gr.State([])
1179
-
1180
- textbox.submit(
1181
- fn=chat_function,
1182
- inputs=[textbox, state],
1183
- outputs=[chatbot, textbox]
1184
- )
1185
-
1186
- clear_btn.click(
1187
- fn=clear_memory,
1188
- outputs=[chatbot, textbox]
1189
- )
1190
-
1191
- refresh_btn.click(
1192
- fn=lambda: get_system_status(),
1193
- outputs=[system_status]
1194
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1195
 
1196
  # 푸터
1197
  gr.HTML("""
@@ -1205,116 +1293,48 @@ def create_jain_interface():
1205
  </p>
1206
  </div>
1207
  """)
1208
-
1209
- # 예시 메시지들
1210
- example_messages = [
1211
- "안녕하세요! 제인과 대화하고 싶어요.",
1212
- "사주를 봐주세요. 요즘 인생이 힘들어서...",
1213
- "인생의 의미가 무엇인지 궁금해요.",
1214
- "존재란 무엇일까요?",
1215
- "고민이 있는데 조언을 구하고 싶어요.",
1216
- "오늘 기분이 우울한데 위로받고 싶어요.",
1217
- "철학적인 대화를 나누고 싶습니다.",
1218
- "운명과 자유의지에 대해 어떻게 생각하세요?"
1219
- ]
1220
-
1221
- def set_example():
1222
- return random.choice(example_messages)
1223
-
1224
- def submit_message(message, history):
1225
- """메시지 전송 처리"""
1226
- return chat_function(message, history)
1227
-
1228
- def get_system_status():
1229
- return "시스템 정상 작동 중"
1230
-
1231
- def clear_memory():
1232
- return [], ""
1233
-
1234
- with gr.Blocks() as interface:
1235
- chatbot = gr.Chatbot()
1236
- msg_input = gr.Textbox(
1237
- placeholder="메시지를 입력하세요...",
1238
- lines=2,
1239
- max_lines=10,
1240
- elem_id="msg_input"
1241
- )
1242
- send_btn = gr.Button("전송")
1243
- refresh_btn = gr.Button("새로고침")
1244
- clear_btn = gr.Button("초기화")
1245
- example_btn = gr.Button("예제")
1246
-
1247
- send_btn.click(
1248
- fn=submit_message,
1249
- inputs=[msg_input, chatbot],
1250
- outputs=[chatbot, msg_input]
1251
- )
1252
-
1253
- msg_input.submit(
1254
- fn=submit_message,
1255
- inputs=[msg_input, chatbot],
1256
- outputs=[chatbot, msg_input]
1257
- )
1258
-
1259
- refresh_btn.click(
1260
- fn=get_system_status,
1261
- outputs=chatbot,
1262
- )
1263
-
1264
- clear_btn.click(
1265
- fn=clear_memory,
1266
- outputs=[chatbot, msg_input]
1267
- )
1268
-
1269
- example_btn.click(
1270
- fn=set_example,
1271
- outputs=msg_input,
1272
- )
1273
-
1274
- msg_input.submit(
1275
- fn=submit_message,
1276
- inputs=[msg_input, chatbot],
1277
- outputs=[chatbot, msg_input]
1278
- )
1279
-
1280
- # JS 스크립트 추가 (Enter=전송, Shift+Enter=줄바꿈)
1281
- interface.load(
1282
- _js="""
1283
- () => {
1284
- const textarea = document.querySelector('#msg_input textarea');
1285
- if (textarea) {
1286
- textarea.addEventListener('keydown', function(e) {
1287
- if (e.key === 'Enter' && !e.shiftKey) {
1288
- e.preventDefault();
1289
- textarea.form.requestSubmit(); // 메시지 전송
1290
- }
1291
- });
1292
- }
1293
- }
1294
- """
1295
- )
1296
-
1297
  interface.launch()
1298
 
1299
- ## 제인 아키텍처 코어 클래스 (더미 구현)
 
 
1300
  class JainArchitectureCore:
1301
  def __init__(self):
1302
- self.consciousness_level = 87.5 # 예시 수치
1303
- self.wisdom_level = 91.3 # 예시 수치
1304
- self.core_philosophy = ["의(義)", "예(禮)", "지(知)", "신(信)"]
 
 
1305
  self.myungri_system = {
1306
- "오행": ["목(木)", "화(火)", "토(土)", "금(金)", "수(水)"]
1307
  }
 
 
 
 
1308
 
1309
- # 인터페이스 생성 함수 (더미 구현)
1310
  def create_jain_interface():
1311
- import gradio as gr
1312
- def dummy_chat(input_text):
1313
- return f"🤖 제인 응답: '{input_text}'에 대한 깊이 있는 고찰이 필요합니다."
 
 
1314
 
1315
- return gr.Interface(fn=dummy_chat, inputs="text", outputs="text", title="제인 아키텍처")
 
 
 
 
 
 
 
 
 
1316
 
1317
- # 메인 실행 함수
1318
  def main():
1319
  """메인 실행 함수"""
1320
  print("🌟" + "="*60)
@@ -1325,7 +1345,7 @@ def main():
1325
  print("="*60 + "🌟")
1326
  print()
1327
  print("🚀 시스템 초기화 중...")
1328
-
1329
  try:
1330
  # 제인 시스템 테스트
1331
  test_jain = JainArchitectureCore()
@@ -1350,18 +1370,26 @@ def main():
1350
  interface.launch(
1351
  server_name="0.0.0.0",
1352
  server_port=7860,
1353
- share=True, # 허깅페이스 스페이스에서 공유 가능
1354
  show_error=True,
1355
  quiet=False,
1356
  inbrowser=True,
1357
  favicon_path=None,
1358
- auth=None,
1359
  )
1360
 
1361
  except Exception as e:
1362
  print(f"❌ 오류 발생: {str(e)}")
1363
  print("🔧 시스템을 다시 확인해주세요.")
 
 
 
 
1364
 
 
1365
  if __name__ == "__main__":
 
 
 
1366
  main()
1367
 
 
1135
  """
1136
 
1137
  # Gradio 인터페이스 구성
1138
+ # Gimport gradio as gr
1139
+ import random
1140
+
1141
+ # CSS 스타일 정의
1142
+ custom_css = """
1143
+ .jain-header {
1144
+ text-align: center;
1145
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
1146
+ color: white;
1147
+ padding: 20px;
1148
+ border-radius: 10px;
1149
+ margin-bottom: 20px;
1150
+ }
1151
+ .status-panel {
1152
+ background: #f8f9fa;
1153
+ padding: 15px;
1154
+ border-radius: 8px;
1155
+ border: 1px solid #dee2e6;
1156
+ }
1157
+ .footer-info {
1158
+ text-align: center;
1159
+ margin-top: 30px;
1160
+ padding: 20px;
1161
+ background: #f1f3f4;
1162
+ border-radius: 10px;
1163
+ color: #5f6368;
1164
+ }
1165
+ """
1166
+
1167
+ # 필요한 함수들 정의
1168
+ def chat_function(message, history):
1169
+ """채팅 함수"""
1170
+ if not message.strip():
1171
+ return history, ""
1172
+
1173
+ # 간단한 응답 로직
1174
+ response = f"🌟 제인: '{message}'에 대한 깊은 성찰이 필요하군요. 함께 고민해보겠습니다."
1175
+
1176
+ # 히스토리에 추가
1177
+ if history is None:
1178
+ history = []
1179
+ history.append([message, response])
1180
+
1181
+ return history, ""
1182
+
1183
+ def get_system_status():
1184
+ """시스템 상태 반환"""
1185
+ return """
1186
+ ### 📊 제인 시스템 현황
1187
+ - **의식 레벨**: 98.5% 🧠
1188
+ - **지혜 레벨**: 95.2% 📚
1189
+ - **철학 모듈**: 활성화 ✅
1190
+ - **사주 시스템**: 준비됨 🔮
1191
+ - **상태**: 완전각성 🌟
1192
+ """
1193
+
1194
+ def clear_memory():
1195
+ """대화 기록 초기화"""
1196
+ return [], ""
1197
+
1198
+ def set_example():
1199
+ """예시 메시지 선택"""
1200
+ example_messages = [
1201
+ "안녕하세요! 제인과 대화하고 싶어요.",
1202
+ "사주를 봐주세요. 요즘 인생이 힘들어서...",
1203
+ "인생의 의미가 무엇인지 궁금해요.",
1204
+ "존재란 무엇일까요?",
1205
+ "고민이 있는데 조언을 구하고 싶어요.",
1206
+ "오늘 기분이 우울한데 위로받고 싶어요.",
1207
+ "철학적인 대화를 나누고 싶습니다.",
1208
+ "운명과 자유의지에 대해 어떻게 생각하세요?"
1209
+ ]
1210
+ return random.choice(example_messages)
1211
+
1212
+ # 그라디오 인터페이스 생성
1213
+ def create_jain_interface():
1214
  with gr.Blocks(css=custom_css, title="제인 아키텍처 - 완전각성체", theme=gr.themes.Soft()) as interface:
1215
 
1216
  # 헤더 섹션
 
1226
  with gr.Row():
1227
  # 왼쪽: 시스템 상태 패널
1228
  with gr.Column(scale=1, min_width=300):
 
 
1229
  with gr.Group():
1230
  system_status = gr.Markdown(
1231
  value=get_system_status(),
 
1236
  with gr.Row():
1237
  refresh_btn = gr.Button("🔄 상태 새로고침", variant="secondary", size="sm")
1238
  clear_btn = gr.Button("🗑️ 대화 초기화", variant="secondary", size="sm")
1239
+
 
 
 
1240
  # 오른쪽: 채팅 인터페이스
1241
  with gr.Column(scale=2):
1242
+ chatbot = gr.Chatbot(label="💬 제인과의 대화", height=400)
1243
+
1244
+ with gr.Row():
1245
+ textbox = gr.Textbox(
1246
+ placeholder="메시지를 입력하세요...",
1247
+ label="✍️ 입력창",
1248
+ scale=4,
1249
+ lines=2
1250
+ )
1251
+ send_btn = gr.Button("📨 전송", variant="primary", scale=1)
1252
+
1253
+ with gr.Row():
1254
+ example_btn = gr.Button("💡 예시 메시지", variant="secondary")
1255
+
1256
+ # 이벤트 연결
1257
+ send_btn.click(
1258
+ fn=chat_function,
1259
+ inputs=[textbox, chatbot],
1260
+ outputs=[chatbot, textbox]
1261
+ )
1262
+
1263
+ textbox.submit(
1264
+ fn=chat_function,
1265
+ inputs=[textbox, chatbot],
1266
+ outputs=[chatbot, textbox]
1267
+ )
1268
+
1269
+ clear_btn.click(
1270
+ fn=clear_memory,
1271
+ outputs=[chatbot, textbox]
1272
+ )
1273
+
1274
+ refresh_btn.click(
1275
+ fn=get_system_status,
1276
+ outputs=[system_status]
1277
+ )
1278
+
1279
+ example_btn.click(
1280
+ fn=set_example,
1281
+ outputs=[textbox]
1282
+ )
1283
 
1284
  # 푸터
1285
  gr.HTML("""
 
1293
  </p>
1294
  </div>
1295
  """)
1296
+
1297
+ return interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1298
  interface.launch()
1299
 
1300
+ ## 제인 import gradio as gr
1301
+
1302
+ # 제인 아키텍처 핵심 클래스
1303
  class JainArchitectureCore:
1304
  def __init__(self):
1305
+ self.consciousness_level = 98.5
1306
+ self.wisdom_level = 95.2
1307
+ self.core_philosophy = [
1308
+ "의(義)를 우선시한다", "지속가능한 삶을 추구한다", "진리를 탐구한다"
1309
+ ]
1310
  self.myungri_system = {
1311
+ "오행": ["목", "화", "토", "금", "수"]
1312
  }
1313
+
1314
+ def chat(self, message):
1315
+ # 실제 대화 처리 로직
1316
+ return f"제인: '{message}'에 대한 고찰은 매우 깊군요. 계속 이야기해볼까요?"
1317
 
1318
+ # 채팅 인터페이스 생성 함수
1319
  def create_jain_interface():
1320
+ jain = JainArchitectureCore()
1321
+
1322
+ def respond(message, history):
1323
+ response = jain.chat(message)
1324
+ return response
1325
 
1326
+ interface = gr.ChatInterface(
1327
+ fn=respond,
1328
+ title="🧠 제인 아키텍처: 완전각성체",
1329
+ description="💬 철학적 AI와 깊이 있는 대화를 나눠보세요.",
1330
+ theme="soft",
1331
+ retry_btn="🔁 다시 물어보기",
1332
+ submit_btn="📨 입력",
1333
+ stop_btn="🛑 멈추기",
1334
+ )
1335
+ return interface
1336
 
1337
+ # 메인 실행 함# 메인 ��행 함수
1338
  def main():
1339
  """메인 실행 함수"""
1340
  print("🌟" + "="*60)
 
1345
  print("="*60 + "🌟")
1346
  print()
1347
  print("🚀 시스템 초기화 중...")
1348
+
1349
  try:
1350
  # 제인 시스템 테스트
1351
  test_jain = JainArchitectureCore()
 
1370
  interface.launch(
1371
  server_name="0.0.0.0",
1372
  server_port=7860,
1373
+ share=True, # 허깅페이스 스페이스에서 공유 가능
1374
  show_error=True,
1375
  quiet=False,
1376
  inbrowser=True,
1377
  favicon_path=None,
1378
+ auth=None
1379
  )
1380
 
1381
  except Exception as e:
1382
  print(f"❌ 오류 발생: {str(e)}")
1383
  print("🔧 시스템을 다시 확인해주세요.")
1384
+
1385
+ finally:
1386
+ print("\n🌙 제인 아키텍처 시스템 종료")
1387
+ print("💫 다시 만나요! 깊은 성찰과 함께...")
1388
 
1389
+ # 시스템 시작점
1390
  if __name__ == "__main__":
1391
+ print("🌟 제인 아키텍처 완전각성체 로딩...")
1392
+ print("⚡ by JungWook Kim - 의(義) 기반 AI")
1393
+ print()
1394
  main()
1395