Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,11 +9,19 @@ def load_system_role(role_name):
|
|
| 9 |
roles = json.load(file)
|
| 10 |
return roles.get(role_name, "Ты помощник по умолчанию.")
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# Функция для генерации текста
|
| 13 |
-
def generate(description,
|
| 14 |
if not description:
|
| 15 |
return None, None
|
| 16 |
|
|
|
|
|
|
|
| 17 |
headers = {
|
| 18 |
'Content-Type': 'application/json',
|
| 19 |
'Authorization': f'Bearer {os.getenv("API_KEY")}'
|
|
@@ -52,26 +60,29 @@ css_url = "https://neurixyufi-aihub.static.hf.space/style.css"
|
|
| 52 |
response = requests.get(css_url)
|
| 53 |
css = response.text + ".gradio-container{max-width: 700px !important} h1{text-align:center}"
|
| 54 |
|
|
|
|
|
|
|
|
|
|
| 55 |
# UI
|
| 56 |
with gr.Blocks(css=css) as demo:
|
| 57 |
gr.Markdown("# EasyGemini")
|
| 58 |
with gr.Tab("Запрос"):
|
| 59 |
with gr.Row():
|
| 60 |
promt = gr.Textbox(show_label=True, label="Запрос", lines=3)
|
| 61 |
-
with gr.Tab("Настройки"):
|
| 62 |
with gr.Row():
|
| 63 |
with gr.Accordion(label="Помощник", open=True):
|
| 64 |
-
helper_role = gr.Radio(show_label=True, label="Выберите помощника", interactive=True, choices=
|
|
|
|
| 65 |
with gr.Row():
|
| 66 |
-
max_tokens = gr.Slider(show_label=True, label="Максимальное количество
|
| 67 |
with gr.Row():
|
| 68 |
text_button = gr.Button("Генерация", variant='primary')
|
| 69 |
with gr.Row():
|
| 70 |
with gr.Tab("Ответ"):
|
| 71 |
text_output = gr.Markdown(show_label=False, value="**Здравствуйте!** Чем я могу Вам помочь сегодня?")
|
| 72 |
-
with gr.Accordion(label="Без
|
| 73 |
text_output_nm = gr.Textbox(show_label=False, value="**Здравствуйте!** Чем я могу Вам помочь сегодня?", lines=3)
|
| 74 |
|
| 75 |
text_button.click(generate, inputs=[promt, helper_role, max_tokens], outputs=[text_output, text_output_nm])
|
| 76 |
|
| 77 |
-
demo.queue(api_open=False, max_size=150).launch()
|
|
|
|
| 9 |
roles = json.load(file)
|
| 10 |
return roles.get(role_name, "Ты помощник по умолчанию.")
|
| 11 |
|
| 12 |
+
# Функция для загрузки названий ролей из JSON файла
|
| 13 |
+
def load_role_names():
|
| 14 |
+
with open('system_roles.json', 'r', encoding='utf-8') as file:
|
| 15 |
+
roles = json.load(file)
|
| 16 |
+
return list(roles.keys())
|
| 17 |
+
|
| 18 |
# Функция для генерации текста
|
| 19 |
+
def generate(description, system_role_name, max_tokens):
|
| 20 |
if not description:
|
| 21 |
return None, None
|
| 22 |
|
| 23 |
+
system_role = load_system_role(system_role_name)
|
| 24 |
+
|
| 25 |
headers = {
|
| 26 |
'Content-Type': 'application/json',
|
| 27 |
'Authorization': f'Bearer {os.getenv("API_KEY")}'
|
|
|
|
| 60 |
response = requests.get(css_url)
|
| 61 |
css = response.text + ".gradio-container{max-width: 700px !important} h1{text-align:center}"
|
| 62 |
|
| 63 |
+
# Загрузка названий ролей из JSON файла
|
| 64 |
+
role_names = load_role_names()
|
| 65 |
+
|
| 66 |
# UI
|
| 67 |
with gr.Blocks(css=css) as demo:
|
| 68 |
gr.Markdown("# EasyGemini")
|
| 69 |
with gr.Tab("Запрос"):
|
| 70 |
with gr.Row():
|
| 71 |
promt = gr.Textbox(show_label=True, label="Запрос", lines=3)
|
|
|
|
| 72 |
with gr.Row():
|
| 73 |
with gr.Accordion(label="Помощник", open=True):
|
| 74 |
+
helper_role = gr.Radio(show_label=True, label="Выберите помощника", interactive=True, choices=role_names, value=role_names[0])
|
| 75 |
+
with gr.Tab("Настройки"):
|
| 76 |
with gr.Row():
|
| 77 |
+
max_tokens = gr.Slider(show_label=True, label="Максимальное количество символов", minimum=100, maximum=8000, value=4000, step=1)
|
| 78 |
with gr.Row():
|
| 79 |
text_button = gr.Button("Генерация", variant='primary')
|
| 80 |
with gr.Row():
|
| 81 |
with gr.Tab("Ответ"):
|
| 82 |
text_output = gr.Markdown(show_label=False, value="**Здравствуйте!** Чем я могу Вам помочь сегодня?")
|
| 83 |
+
with gr.Accordion(label="Без форматирования", open=False):
|
| 84 |
text_output_nm = gr.Textbox(show_label=False, value="**Здравствуйте!** Чем я могу Вам помочь сегодня?", lines=3)
|
| 85 |
|
| 86 |
text_button.click(generate, inputs=[promt, helper_role, max_tokens], outputs=[text_output, text_output_nm])
|
| 87 |
|
| 88 |
+
demo.queue(api_open=False, max_size=150).launch()
|