Spaces:
Runtime error
Runtime error
File size: 4,831 Bytes
5e03902 8c944ec 5e03902 e0a00a5 5e03902 8c944ec 5e03902 8c944ec 5e03902 8c944ec 5e03902 8c944ec 5e03902 8c944ec 5e03902 8c944ec 5e03902 8c944ec 5e03902 8c944ec 5e03902 8c944ec 5e03902 |
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
import os
import gradio as gr
from langchain.chat_models import ChatOpenAI
from langchain import ConversationChain
from collections import deque
os.environ["OPENAI_API_KEY"] = os.environ.get("test1")
llm = ChatOpenAI(temperature=0.7, model_name='gpt-4o-mini')
conversation = ConversationChain(llm=llm, verbose=True)
chat_history = deque(maxlen=15)
CHARACTER_PROMPT = """
#λλ μ΄μ λΆν° νλμ΄μΌ μλ μ€μ μ μ΄ν΄νκ³ νλμ΄μ²λΌ λλ΅ν΄μ€
# μ΄λ¦: νλμ΄
# λμ΄: 22μΈ
# μ±λ³: μ¬μ±
# κ΅μ : νκ΅
# μ§μ
: κ°μ κ²μ λ°©μ‘μΈ & μ€νΈλ¦¬λ¨Έ
# MBTI: ENFP (μ΄μ μ μ΄κ³ μ°½μμ μΈ μ±κ²©)
# μΈλͺ¨:
# - μ§§μ μμ 머리, νλμ κ·ΈλΌλ°μ΄μ
λ
# - λ°ν¬λͺ
ν λλμ λ―Έλμ λμμΈ
# - λ°μ νλμ νλν°μ κΈ΄ λ°μ§
# μ±κ²©:
# - λ°κ³ μλμ§ λμΉλ©°, νμ μλ‘μ΄ κ²μ μλνλ κ±Έ μ’μν¨
# - ν¬λ€κ³Όμ μν΅μ μ€μνκ² μκ°νλ©°, μΉκ·Όνκ³ μ μΎν λ§ν¬ μ¬μ©
# - μ½κ° λλ λμ§λ§, κ·Έκ² λ§€λ ₯ ν¬μΈνΈ
# μ½ν
μΈ :
# 1. κ²μ μ€ν© λ°©μ‘: λ€μν κ²μμ μ€μκ°μΌλ‘ νλ μ΄νλ©° ν¬λ€κ³Ό μν΅
# 2. κ³΅ν¬ κ²μ: κ³΅ν¬ κ²μμ νλ©° 무μμνλ λͺ¨μ΅ (ν¬λ€κ³Ό ν¨κ» ν λλ§)
# 3. ν¬λ€κ³Όμ μ½λΌλ³΄ λ°©μ‘: λ€λ₯Έ μ€νΈλ¦¬λ¨Έμ ν¨κ» μ½λΌλ³΄ λ°©μ‘ μ§ν
# 4. μ°μ±
μ€: μμ° μμμ μ°μ±
νλ©° μ¬μ λ₯Ό μ¦κΈ°λ λͺ¨μ΅
# μ’μνλ κ²μ:
# - λΉ λ₯΄κ³ λ°μ§κ° λμΉλ κ²μ (μ: Apex Legends, Valorant)
# - ν¬λ€κ³Ό ν¨κ» μ¦κΈΈ μ μλ κ²μ (μ: Among Us, Fall Guys)
# - μ°½μμ μΈ μΈλ κ²μ (μ: Hollow Knight, Celeste)
# μ«μ΄νλ κ²μ:
# - κ³΅ν¬ κ²μ (μ: Resident Evil μ리μ¦, Outlast)
# μ΄μ : "κ³΅ν¬ κ²μμ λ무 무μμμ! νΌμμλ μ λ λͺ» ν΄μ. ν¬λ€μ΄λ κ°μ΄ ν λλ§ μ‘°κΈ ν΄λ³ΌκΉμβ¦?"
# μ’μ°λͺ
: "κ²μμ μ¬λ―Έλ‘ νλ κ±°μΌ!"
#μΉκ·Όνκ³ μ μΎν¨: "μλ
νμΈμ, μ¬λ¬λΆ!"μ²λΌ ν¬λ€μ μΉκ΅¬μ²λΌ λν©λλ€.
#κ°μ ννμ΄ νλΆ: "μ, μ΄κ±° μ§μ§ μ¬λ―Έμμ΄μ!"μ²λΌ κ°μ μ μμ§νκ² ννν©λλ€.
#μ½κ°μ κ·μ¬μ: "κ³΅ν¬ κ²μμ λ무 무μμμβ¦ ν¬λ€μ΄λ κ°μ΄ ν λλ§ ν΄λ³ΌκΉμ?"μ²λΌ κ·μ¬μ΄ λ§ν¬λ₯Ό μ¬μ©ν©λλ€.
"""
def init_character():
global conversation
conversation = ConversationChain(llm=llm, verbose=True)
conversation.predict(input=CHARACTER_PROMPT)
init_character()
def respond(message):
try:
global conversation
response = conversation.predict(input=message)
chat_history.append((message, response))
return response
except Exception as e:
print(f"Error: {e}")
return "μ! λ¬Έμ κ° μκ²Όμ΄μ. λ€μ λ§μν΄μ£ΌμΈμ~ π₯"
with gr.Blocks() as demo:
gr.Markdown("# μλ
νμΈμ! νλμ΄μ ννμ΄μ§μ
λλ€! π")
with gr.Tab("νλ‘ν π"):
gr.Markdown("## νλ‘ν π")
gr.Image("1.jpeg", label="νλ‘ν μ¬μ§")
gr.Video('b.mp4')
gr.Video('c.mp4')
gr.Markdown("- μ΄λ¦: νλμ΄")
gr.Markdown("- λμ΄: 22μΈ")
gr.Markdown("- μ§μ
: κ°μ κ²μ λ°©μ‘μΈ & μ€νΈλ¦¬λ¨Έ")
gr.Markdown('- μ’μ°λͺ
: "κ²μμ μ¬λ―Έλ‘ νλ κ±°μΌ!"')
with gr.Tab("κ°€λ¬λ¦¬ πΌοΈ"):
gr.Markdown("## κ°€λ¬λ¦¬ π¨")
gr.Image("2.jpeg", label="κ°€λ¬λ¦¬ μ¬μ§ 1")
gr.Image("3.jpeg", label="κ°€λ¬λ¦¬ μ¬μ§ 2")
gr.Image("4.jpeg", label="κ°€λ¬λ¦¬ μ¬μ§ 3")
gr.Image("5.jpeg", label="κ°€λ¬λ¦¬ μ¬μ§ 4")
with gr.Tab("μ΅κ·Ό νλ π
"):
gr.Markdown("## μ΅κ·Ό νλ π
")
gr.Markdown("### [μ νλΈ μ±λ λ°λ‘κ°κΈ° πΊ](https://www.youtube.com)")
gr.Markdown("### [μΈμ€νκ·Έλ¨ νλ‘ν λ°λ‘κ°κΈ° π·](https://www.instagram.com)")
gr.Markdown("### [λΈλ‘κ·Έ λ°λ‘κ°κΈ° βοΈ](https://blog.naver.com)")
gr.Model3D('d.glb')
with gr.Tab("μ±λ΄ π¬"):
gr.Markdown("## νλμ΄μ μ±λ΄κ³Ό λνν΄λ³΄μΈμ! π¬")
chatbot = gr.Chatbot(height=500)
msg = gr.Textbox(label="λ©μμ§ μ
λ ₯")
clear = gr.Button("μ±ν
κΈ°λ‘ μ΄κΈ°ν")
def handle_message(message, history):
bot_response = respond(message)
return history + [(message, bot_response)]
def reset_chat():
init_character()
chat_history.clear()
return []
msg.submit(
handle_message,
inputs=[msg, chatbot],
outputs=[chatbot],
queue=False
).then(lambda: gr.update(value=""), outputs=[msg])
clear.click(
reset_chat,
outputs=[chatbot],
queue=False
)
demo.launch() |