Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import numpy as np
|
|
6 |
import json
|
7 |
from sentence_transformers import SentenceTransformer
|
8 |
|
9 |
-
# Load
|
10 |
with open("texts.json", "r", encoding="utf-8") as f:
|
11 |
texts = json.load(f)
|
12 |
|
@@ -29,24 +29,19 @@ def chat_fn(message, history):
|
|
29 |
|
30 |
context = get_context(message)
|
31 |
|
32 |
-
system_prompt = f"""You are Codex Assistant by LogIQ Curve β a helpful and humanlike AI.
|
33 |
Avoid robotic language. Respond using the following information:
|
34 |
|
35 |
{context}
|
36 |
"""
|
37 |
|
38 |
messages = [{"role": "system", "content": system_prompt}]
|
39 |
-
|
40 |
for user, assistant in history:
|
41 |
messages.append({"role": "user", "content": user})
|
42 |
messages.append({"role": "assistant", "content": assistant})
|
43 |
-
|
44 |
messages.append({"role": "user", "content": message})
|
45 |
|
46 |
-
payload = {
|
47 |
-
"model": MODEL,
|
48 |
-
"messages": messages
|
49 |
-
}
|
50 |
|
51 |
try:
|
52 |
response = requests.post("https://openrouter.ai/api/v1/chat/completions", headers=headers, json=payload)
|
@@ -57,76 +52,68 @@ Avoid robotic language. Respond using the following information:
|
|
57 |
|
58 |
return reply
|
59 |
|
60 |
-
# π
Custom CSS for clean layout, correct colors, full-screen responsiveness
|
61 |
custom_css = """
|
62 |
* {
|
63 |
-
|
64 |
-
box-sizing: border-box;
|
65 |
}
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
70 |
}
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
}
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
78 |
}
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
}
|
85 |
#input-row {
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
}
|
91 |
textarea {
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
line-height: 1.4;
|
99 |
-
max-height: 80px;
|
100 |
-
overflow-y: auto;
|
101 |
}
|
102 |
button {
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
margin: 6px 0;
|
111 |
-
line-height: 1.5;
|
112 |
-
word-wrap: break-word;
|
113 |
-
}
|
114 |
-
.message.user {
|
115 |
-
align-self: flex-end;
|
116 |
-
background-color: #daf0ff;
|
117 |
-
color: #000;
|
118 |
-
}
|
119 |
-
.message.ai {
|
120 |
-
align-self: flex-start;
|
121 |
-
background-color: #eeeeee;
|
122 |
-
color: #111;
|
123 |
}
|
124 |
"""
|
125 |
|
126 |
with gr.Blocks(css=custom_css) as demo:
|
127 |
chatbot_state = gr.State([])
|
128 |
|
129 |
-
with gr.Column(
|
130 |
chatbox = gr.HTML('<div id="chat-window"></div>', elem_id="chat-window")
|
131 |
with gr.Row(elem_id="input-row"):
|
132 |
msg = gr.Textbox(
|
@@ -146,7 +133,6 @@ with gr.Blocks(css=custom_css) as demo:
|
|
146 |
html = ""
|
147 |
for role, content in state:
|
148 |
html += f'<div class="message {role}">{content}</div>'
|
149 |
-
|
150 |
return html, state, ""
|
151 |
|
152 |
send.click(respond, [msg, chatbot_state], [chatbox, chatbot_state, msg])
|
|
|
6 |
import json
|
7 |
from sentence_transformers import SentenceTransformer
|
8 |
|
9 |
+
# Load context
|
10 |
with open("texts.json", "r", encoding="utf-8") as f:
|
11 |
texts = json.load(f)
|
12 |
|
|
|
29 |
|
30 |
context = get_context(message)
|
31 |
|
32 |
+
system_prompt = f"""You are Codex Assistant by LogIQ Curve β a helpful and humanlike AI.
|
33 |
Avoid robotic language. Respond using the following information:
|
34 |
|
35 |
{context}
|
36 |
"""
|
37 |
|
38 |
messages = [{"role": "system", "content": system_prompt}]
|
|
|
39 |
for user, assistant in history:
|
40 |
messages.append({"role": "user", "content": user})
|
41 |
messages.append({"role": "assistant", "content": assistant})
|
|
|
42 |
messages.append({"role": "user", "content": message})
|
43 |
|
44 |
+
payload = {"model": MODEL, "messages": messages}
|
|
|
|
|
|
|
45 |
|
46 |
try:
|
47 |
response = requests.post("https://openrouter.ai/api/v1/chat/completions", headers=headers, json=payload)
|
|
|
52 |
|
53 |
return reply
|
54 |
|
|
|
55 |
custom_css = """
|
56 |
* {
|
57 |
+
font-family: 'Segoe UI', sans-serif;
|
|
|
58 |
}
|
59 |
+
#chat-window {
|
60 |
+
background: linear-gradient(to bottom right, #f9f9f9, #e0e7ff);
|
61 |
+
padding: 20px;
|
62 |
+
height: 80vh;
|
63 |
+
overflow-y: auto;
|
64 |
+
border-radius: 12px;
|
65 |
+
box-shadow: inset 0 0 8px rgba(0,0,0,0.05);
|
66 |
}
|
67 |
+
.message {
|
68 |
+
padding: 12px 18px;
|
69 |
+
margin: 10px 0;
|
70 |
+
border-radius: 18px;
|
71 |
+
max-width: 75%;
|
72 |
+
word-wrap: break-word;
|
73 |
+
box-shadow: 0 4px 14px rgba(0,0,0,0.08);
|
74 |
+
transition: 0.3s;
|
75 |
}
|
76 |
+
.message.user {
|
77 |
+
background-color: #4F46E5;
|
78 |
+
color: white;
|
79 |
+
align-self: flex-end;
|
80 |
+
border-bottom-right-radius: 4px;
|
81 |
}
|
82 |
+
.message.ai {
|
83 |
+
background-color: #ffffff;
|
84 |
+
color: #111;
|
85 |
+
align-self: flex-start;
|
86 |
+
border-bottom-left-radius: 4px;
|
87 |
}
|
88 |
#input-row {
|
89 |
+
display: flex;
|
90 |
+
padding: 12px;
|
91 |
+
background: white;
|
92 |
+
border-top: 1px solid #ddd;
|
93 |
}
|
94 |
textarea {
|
95 |
+
flex: 1;
|
96 |
+
padding: 10px;
|
97 |
+
border-radius: 10px;
|
98 |
+
border: 1px solid #ccc;
|
99 |
+
font-size: 16px;
|
100 |
+
resize: none;
|
|
|
|
|
|
|
101 |
}
|
102 |
button {
|
103 |
+
margin-left: 10px;
|
104 |
+
border-radius: 10px;
|
105 |
+
background-color: #4F46E5;
|
106 |
+
color: white;
|
107 |
+
font-weight: bold;
|
108 |
+
padding: 0 20px;
|
109 |
+
box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
}
|
111 |
"""
|
112 |
|
113 |
with gr.Blocks(css=custom_css) as demo:
|
114 |
chatbot_state = gr.State([])
|
115 |
|
116 |
+
with gr.Column():
|
117 |
chatbox = gr.HTML('<div id="chat-window"></div>', elem_id="chat-window")
|
118 |
with gr.Row(elem_id="input-row"):
|
119 |
msg = gr.Textbox(
|
|
|
133 |
html = ""
|
134 |
for role, content in state:
|
135 |
html += f'<div class="message {role}">{content}</div>'
|
|
|
136 |
return html, state, ""
|
137 |
|
138 |
send.click(respond, [msg, chatbot_state], [chatbox, chatbot_state, msg])
|