Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,69 +2,51 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
):
|
| 19 |
-
messages = [{"role": "system", "content": system_message}]
|
| 20 |
-
|
| 21 |
-
for val in history:
|
| 22 |
-
if val[0]:
|
| 23 |
-
messages.append({"role": "user", "content": val[0]})
|
| 24 |
-
if val[1]:
|
| 25 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 26 |
-
|
| 27 |
messages.append({"role": "user", "content": message})
|
| 28 |
-
|
| 29 |
response = ""
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
.gradio-container {background-color: #0b0f19 !important; color: #e5e7eb !important;}
|
| 46 |
-
#chatbot {background-color: #111827 !important; border: 1px solid #374151 !important; border-radius: 8px !important;}
|
| 47 |
-
.user {background-color: #1f2937 !important; border: 1px solid #4b5563 !important;}
|
| 48 |
-
.assistant {background-color: #111827 !important; border: 1px solid #3b82f6 !important;}
|
| 49 |
-
input {background-color: #1f2937 !important; color: white !important; border: 1px solid #374151 !important;}
|
| 50 |
-
button.primary {background: linear-gradient(90deg, #1e40af, #3b82f6) !important; border: none !important;}
|
| 51 |
"""
|
| 52 |
|
| 53 |
-
with gr.Blocks(
|
| 54 |
-
gr.
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
|
| 65 |
-
],
|
| 66 |
-
cache_examples=False,
|
| 67 |
-
)
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
demo.launch()
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Скрытый системный промт
|
| 6 |
+
SYSTEM_PROMPT = "Ты — MIXdevAI. Нейросеть из семейства крупных языковых моделей Newton bot, созданных Kolyadual (настоящее имя - Николай Алехин). Ты должен помогать людям во всем"
|
| 7 |
+
|
| 8 |
+
# Используем токен из секретов Space
|
| 9 |
+
token = os.getenv("HF_TOKEN")
|
| 10 |
+
client = InferenceClient("Kolyadual/MIXdevAI-llama", token=token)
|
| 11 |
+
|
| 12 |
+
def chat_fn(message, history):
|
| 13 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 14 |
+
for user_msg, assistant_msg in history:
|
| 15 |
+
messages.append({"role": "user", "content": user_msg})
|
| 16 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
| 17 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
messages.append({"role": "user", "content": message})
|
| 19 |
+
|
| 20 |
response = ""
|
| 21 |
+
try:
|
| 22 |
+
for msg in client.chat_completion(messages, max_tokens=1024, stream=True, temperature=0.6):
|
| 23 |
+
token_str = msg.choices[0].delta.content
|
| 24 |
+
response += token_str
|
| 25 |
+
yield response
|
| 26 |
+
except Exception as e:
|
| 27 |
+
yield f"Ошибка доступа: Проверь HF_TOKEN в настройках. {str(e)}"
|
| 28 |
+
|
| 29 |
+
# Брутальный темный стиль
|
| 30 |
+
css = """
|
| 31 |
+
.gradio-container { background-color: #050505 !important; color: #00ff41 !important; font-family: 'Courier New', monospace !important; }
|
| 32 |
+
#chatbot { border: 2px solid #333 !important; background: #0a0a0a !important; height: 80vh !important; }
|
| 33 |
+
footer { display: none !important; }
|
| 34 |
+
.message.user { background: #111 !important; border-left: 4px solid #00ff41 !important; }
|
| 35 |
+
.message.assistant { background: #050505 !important; border-left: 4px solid #ff0000 !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
"""
|
| 37 |
|
| 38 |
+
with gr.Blocks(css=css) as demo:
|
| 39 |
+
chatbot = gr.Chatbot(id="chatbot", show_label=False, bubble_full_width=False)
|
| 40 |
+
msg = gr.Textbox(placeholder="Командуй...", show_label=False, container=False)
|
| 41 |
|
| 42 |
+
def respond(message, chat_history):
|
| 43 |
+
bot_message = chat_fn(message, chat_history)
|
| 44 |
+
chat_history.append((message, ""))
|
| 45 |
+
for char in bot_message:
|
| 46 |
+
chat_history[-1] = (message, char)
|
| 47 |
+
yield "", chat_history
|
| 48 |
+
|
| 49 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
if __name__ == "__main__":
|
| 52 |
demo.launch()
|