Kim Juwon
commited on
Commit
Β·
9846f7e
1
Parent(s):
5b04c4d
update api
Browse files- __pycache__/app.cpython-39.pyc +0 -0
- app.py +18 -12
__pycache__/app.cpython-39.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-39.pyc and b/__pycache__/app.cpython-39.pyc differ
|
|
|
app.py
CHANGED
|
@@ -21,25 +21,27 @@ Please respond in {language}."""
|
|
| 21 |
|
| 22 |
def respond(message, history, agent_type, personality, expertise_level, language, genre, mood):
|
| 23 |
system_message = create_system_prompt(agent_type, personality, expertise_level, language)
|
| 24 |
-
|
| 25 |
messages = [{"role": "system", "content": system_message}]
|
| 26 |
-
|
| 27 |
for val in history:
|
| 28 |
if val[0]:
|
| 29 |
messages.append({"role": "user", "content": val[0]})
|
| 30 |
if val[1]:
|
| 31 |
messages.append({"role": "assistant", "content": val[1]})
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
messages.append({"role": "user", "content": enhanced_message})
|
| 35 |
-
|
| 36 |
payload = {
|
| 37 |
"messages": messages,
|
| 38 |
"max_tokens": 512,
|
| 39 |
"temperature": 0.7,
|
| 40 |
"top_p": 0.95
|
| 41 |
}
|
| 42 |
-
|
| 43 |
try:
|
| 44 |
response = requests.post(
|
| 45 |
MODAL_ENDPOINT,
|
|
@@ -48,9 +50,12 @@ def respond(message, history, agent_type, personality, expertise_level, language
|
|
| 48 |
)
|
| 49 |
response.raise_for_status()
|
| 50 |
result = response.json()
|
| 51 |
-
|
| 52 |
except Exception as e:
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
def reset_chat():
|
| 56 |
return None
|
|
@@ -66,7 +71,6 @@ def show_settings_changed_info(agent_type, personality, expertise_level, languag
|
|
| 66 |
Chat has been reset. Please start a new conversation with the updated settings.
|
| 67 |
"""
|
| 68 |
|
| 69 |
-
# π¨ CSS: μ€μ μ λ ¬ + κ·ΈλΌλ°μ΄μ
ν¨κ³Ό
|
| 70 |
custom_css = """
|
| 71 |
.header-container {
|
| 72 |
text-align: center;
|
|
@@ -95,7 +99,6 @@ custom_css = """
|
|
| 95 |
"""
|
| 96 |
|
| 97 |
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
| 98 |
-
# μ΄λ―Έμ§ URLλ‘ λ체!
|
| 99 |
gr.HTML("""
|
| 100 |
<div class="header-container">
|
| 101 |
<h1>π¬ Personalized Movie Recommender</h1>
|
|
@@ -108,7 +111,10 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
|
| 108 |
chatbot = gr.Chatbot(
|
| 109 |
height=600,
|
| 110 |
show_copy_button=True,
|
| 111 |
-
avatar_images=(
|
|
|
|
|
|
|
|
|
|
| 112 |
bubble_full_width=False
|
| 113 |
)
|
| 114 |
with gr.Row(equal_height=True):
|
|
@@ -158,7 +164,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
|
| 158 |
)
|
| 159 |
expertise_level = gr.Dropdown(
|
| 160 |
choices=["πΌ Beginner", "π Intermediate", "π Expert"],
|
| 161 |
-
label="
|
| 162 |
value="π Intermediate"
|
| 163 |
)
|
| 164 |
language = gr.Dropdown(
|
|
|
|
| 21 |
|
| 22 |
def respond(message, history, agent_type, personality, expertise_level, language, genre, mood):
|
| 23 |
system_message = create_system_prompt(agent_type, personality, expertise_level, language)
|
| 24 |
+
|
| 25 |
messages = [{"role": "system", "content": system_message}]
|
|
|
|
| 26 |
for val in history:
|
| 27 |
if val[0]:
|
| 28 |
messages.append({"role": "user", "content": val[0]})
|
| 29 |
if val[1]:
|
| 30 |
messages.append({"role": "assistant", "content": val[1]})
|
| 31 |
+
|
| 32 |
+
genre_str = ", ".join(genre) if genre else "Any"
|
| 33 |
+
mood_str = ", ".join(mood) if mood else "Any"
|
| 34 |
+
|
| 35 |
+
enhanced_message = f"Genre: {genre_str}\nMood: {mood_str}\nUser request: {message}"
|
| 36 |
messages.append({"role": "user", "content": enhanced_message})
|
| 37 |
+
|
| 38 |
payload = {
|
| 39 |
"messages": messages,
|
| 40 |
"max_tokens": 512,
|
| 41 |
"temperature": 0.7,
|
| 42 |
"top_p": 0.95
|
| 43 |
}
|
| 44 |
+
|
| 45 |
try:
|
| 46 |
response = requests.post(
|
| 47 |
MODAL_ENDPOINT,
|
|
|
|
| 50 |
)
|
| 51 |
response.raise_for_status()
|
| 52 |
result = response.json()
|
| 53 |
+
bot_reply = result.get("response", "Sorry, I couldn't process your request.")
|
| 54 |
except Exception as e:
|
| 55 |
+
bot_reply = f"Error: {str(e)}"
|
| 56 |
+
|
| 57 |
+
history.append((message, bot_reply))
|
| 58 |
+
return history
|
| 59 |
|
| 60 |
def reset_chat():
|
| 61 |
return None
|
|
|
|
| 71 |
Chat has been reset. Please start a new conversation with the updated settings.
|
| 72 |
"""
|
| 73 |
|
|
|
|
| 74 |
custom_css = """
|
| 75 |
.header-container {
|
| 76 |
text-align: center;
|
|
|
|
| 99 |
"""
|
| 100 |
|
| 101 |
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
|
|
|
| 102 |
gr.HTML("""
|
| 103 |
<div class="header-container">
|
| 104 |
<h1>π¬ Personalized Movie Recommender</h1>
|
|
|
|
| 111 |
chatbot = gr.Chatbot(
|
| 112 |
height=600,
|
| 113 |
show_copy_button=True,
|
| 114 |
+
avatar_images=(
|
| 115 |
+
"https://cdn-icons-png.flaticon.com/512/149/149071.png", # User Avatar
|
| 116 |
+
"https://cdn-icons-png.flaticon.com/512/3135/3135715.png" # Bot Avatar
|
| 117 |
+
),
|
| 118 |
bubble_full_width=False
|
| 119 |
)
|
| 120 |
with gr.Row(equal_height=True):
|
|
|
|
| 164 |
)
|
| 165 |
expertise_level = gr.Dropdown(
|
| 166 |
choices=["πΌ Beginner", "π Intermediate", "π Expert"],
|
| 167 |
+
label="Explanation Level π",
|
| 168 |
value="π Intermediate"
|
| 169 |
)
|
| 170 |
language = gr.Dropdown(
|