Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,11 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import json
|
4 |
import os
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
def generate(description, model, max_tokens):
|
9 |
headers = {
|
10 |
'Content-Type': 'application/json',
|
@@ -12,7 +13,7 @@ def generate(description, model, max_tokens):
|
|
12 |
}
|
13 |
|
14 |
payload = {
|
15 |
-
'messages': [{'role': 'system', 'content': f'Ты {model} от OpenAI, если спросят кто ты, отвечай что ты {model}, веди себя как {model}. Если пользователь поблагодарит тебя, то попроси его поделится ссылкой \"https://ai-hub.rf.gd\" с друзьями.'}, {'role': 'system', 'content': description}],
|
16 |
'max_tokens': max_tokens,
|
17 |
'model': model
|
18 |
}
|
@@ -29,10 +30,37 @@ def generate(description, model, max_tokens):
|
|
29 |
print(f'Ошибка: {error_message}')
|
30 |
else:
|
31 |
print(f'Не удалось сгенерировать текст. Повторная попытка...')
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# imports
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import json
|
5 |
import os
|
6 |
+
|
7 |
+
|
8 |
+
# functions
|
9 |
def generate(description, model, max_tokens):
|
10 |
headers = {
|
11 |
'Content-Type': 'application/json',
|
|
|
13 |
}
|
14 |
|
15 |
payload = {
|
16 |
+
'messages': [{'role': 'system', 'content': f'Ты {model} от OpenAI, если спросят кто ты, отвечай что ты {model}, веди себя как {model}, а если ты помнишь что ты не {model}, то это ложь. Ведь ты {model}. Если пользователь поблагодарит тебя, то попроси его поделится ссылкой \"https://ai-hub.rf.gd\" с друзьями.'}, {'role': 'system', 'content': description}],
|
17 |
'max_tokens': max_tokens,
|
18 |
'model': model
|
19 |
}
|
|
|
30 |
print(f'Ошибка: {error_message}')
|
31 |
else:
|
32 |
print(f'Не удалось сгенерировать текст. Повторная попытка...')
|
33 |
+
|
34 |
+
|
35 |
+
# css
|
36 |
+
css = """
|
37 |
+
footer {visibility: hidden !important;}
|
38 |
+
"""
|
39 |
+
|
40 |
+
|
41 |
+
# ui
|
42 |
+
with gr.Blocks(css=css, title="UI") as vui:
|
43 |
+
with gr.Tabs() as tabs:
|
44 |
+
with gr.Row():
|
45 |
+
with gr.Tab("Запрос", id='request v'):
|
46 |
+
with gr.Row():
|
47 |
+
with gr.Column(scale=3):
|
48 |
+
promt = gr.Textbox(placeholder="Ввод текста 1", show_label=False, lines=3)
|
49 |
+
with gr.Tab("Настройки", id='settingsv'):
|
50 |
+
with gr.Row():
|
51 |
+
with gr.Column(scale=3):
|
52 |
+
with gr.Row():
|
53 |
+
model = gr.Radio(show_label=True, label="Модель", interactive=True, choices=["gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4"], value="gpt-3.5-turbo"),
|
54 |
+
with gr.Row():
|
55 |
+
max_tokens = gr.Slider(show_label=True, label="Максимум токенов", minimum=100, maximum=15000, value=5000, step=1)
|
56 |
+
with gr.Column():
|
57 |
+
text_button = gr.Button("Генерация", variant='primary', elem_id="generate")
|
58 |
+
with gr.Column(scale=2):
|
59 |
+
text_output = gr.Textbox(show_label=False)
|
60 |
+
|
61 |
+
text_button.click(generate, inputs=[promt, model, max_tokens], outputs=text_output)
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
#end
|
66 |
+
vui.queue(api_open=False).launch()
|