Spaces:
Running
Running
Refactor language detection setup and adjust UI layout for system prompt
Browse files
app.py
CHANGED
|
@@ -11,10 +11,14 @@ import os
|
|
| 11 |
import gradio as gr
|
| 12 |
from huggingface_hub import HfApi, InferenceClient
|
| 13 |
from langdetect import detect
|
|
|
|
| 14 |
from dotenv import load_dotenv
|
| 15 |
import requests
|
| 16 |
from datasets import load_dataset
|
| 17 |
|
|
|
|
|
|
|
|
|
|
| 18 |
# Load environment variables
|
| 19 |
load_dotenv()
|
| 20 |
|
|
@@ -895,10 +899,10 @@ with gr.Blocks() as demo:
|
|
| 895 |
clear_btn = gr.Button("Clear")
|
| 896 |
|
| 897 |
with gr.Row(equal_height=True):
|
| 898 |
-
with gr.Column(scale=0.
|
| 899 |
gr.Markdown("") # Empty column for centering
|
| 900 |
|
| 901 |
-
with gr.Column(scale=
|
| 902 |
system_prompt = gr.TextArea(
|
| 903 |
label="System Prompt (editing will change bot behavior)",
|
| 904 |
value=saved_system_prompt,
|
|
@@ -906,7 +910,7 @@ with gr.Blocks() as demo:
|
|
| 906 |
lines=8
|
| 907 |
)
|
| 908 |
|
| 909 |
-
with gr.Column(scale=0.
|
| 910 |
gr.Markdown("") # Empty column for centering
|
| 911 |
|
| 912 |
|
|
@@ -924,11 +928,16 @@ with gr.Blocks() as demo:
|
|
| 924 |
[chatbot, conversation_id, msg]
|
| 925 |
)
|
| 926 |
# Добавляем обработчик изменения промпта
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 927 |
system_prompt.change(
|
| 928 |
save_system_prompt,
|
| 929 |
inputs=[system_prompt],
|
| 930 |
-
outputs=[]
|
| 931 |
-
|
| 932 |
|
| 933 |
clear_btn.click(clear_conversation, None, [chatbot, conversation_id])
|
| 934 |
|
|
|
|
| 11 |
import gradio as gr
|
| 12 |
from huggingface_hub import HfApi, InferenceClient
|
| 13 |
from langdetect import detect
|
| 14 |
+
import langdetect
|
| 15 |
from dotenv import load_dotenv
|
| 16 |
import requests
|
| 17 |
from datasets import load_dataset
|
| 18 |
|
| 19 |
+
# Установка seed для стабильного определения языка
|
| 20 |
+
langdetect.DetectorFactory.seed = 0
|
| 21 |
+
|
| 22 |
# Load environment variables
|
| 23 |
load_dotenv()
|
| 24 |
|
|
|
|
| 899 |
clear_btn = gr.Button("Clear")
|
| 900 |
|
| 901 |
with gr.Row(equal_height=True):
|
| 902 |
+
with gr.Column(scale=0.2):
|
| 903 |
gr.Markdown("") # Empty column for centering
|
| 904 |
|
| 905 |
+
with gr.Column(scale=12):
|
| 906 |
system_prompt = gr.TextArea(
|
| 907 |
label="System Prompt (editing will change bot behavior)",
|
| 908 |
value=saved_system_prompt,
|
|
|
|
| 910 |
lines=8
|
| 911 |
)
|
| 912 |
|
| 913 |
+
with gr.Column(scale=0.2):
|
| 914 |
gr.Markdown("") # Empty column for centering
|
| 915 |
|
| 916 |
|
|
|
|
| 928 |
[chatbot, conversation_id, msg]
|
| 929 |
)
|
| 930 |
# Добавляем обработчик изменения промпта
|
| 931 |
+
system_prompt_status = gr.Textbox(
|
| 932 |
+
label="Status",
|
| 933 |
+
interactive=False,
|
| 934 |
+
visible=True
|
| 935 |
+
)
|
| 936 |
system_prompt.change(
|
| 937 |
save_system_prompt,
|
| 938 |
inputs=[system_prompt],
|
| 939 |
+
outputs=[system_prompt_status]
|
| 940 |
+
)
|
| 941 |
|
| 942 |
clear_btn.click(clear_conversation, None, [chatbot, conversation_id])
|
| 943 |
|