Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -53,15 +53,22 @@ def edit_story(original_story="", edited_prompt=""):
|
|
53 |
except Exception as e:
|
54 |
return f"Ошибка редактирования: {e}"
|
55 |
|
56 |
-
def next_story_func(original_story="", next_prompt=""):
|
57 |
if original_story == "":
|
58 |
return f"Сначала сгенерируйте историю!"
|
59 |
|
60 |
try:
|
61 |
client = InferenceClient(api_key=get_random_api_key())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
messages = [
|
63 |
{"role": "system", "content": "Продли историю, учитывая предоставленные указания. Продливай В ТОЧНОСТИ С КОНЦА, прям с того же символа, слова, предложения. (В начале добавляй новые строки/пробел если надо для отступа)"},
|
64 |
-
{"role": "user", "content":
|
65 |
{"role": "assistant", "content": original_story}
|
66 |
]
|
67 |
completion = client.chat.completions.create(model="Qwen/Qwen2.5-Coder-32B-Instruct", messages=messages, temperature=0.7, max_tokens=1000)
|
@@ -102,6 +109,7 @@ with gr.Blocks(css=css) as demo:
|
|
102 |
edone_button = gr.Button("Принять")
|
103 |
|
104 |
with gr.Tab("Продление"):
|
|
|
105 |
next_prompt = gr.Textbox(label="Введите изменения для продления истории (Необязательно)", placeholder="Продолжи, но что бы было...", lines=5)
|
106 |
next_button = gr.Button("Продлить", variant='primary')
|
107 |
next_story_output = gr.Textbox(label="Продолжение истории", lines=10, placeholder="Здесь будет продолжение вашей истории!")
|
@@ -109,10 +117,10 @@ with gr.Blocks(css=css) as demo:
|
|
109 |
|
110 |
generate_button.click(generate_story, inputs=[prompt, style], outputs=[output_story], concurrency_limit=250)
|
111 |
edit_button.click(edit_story, inputs=[output_story, edited_prompt], outputs=[edited_story], concurrency_limit=250)
|
112 |
-
next_button.click(next_story_func, inputs=[output_story, next_prompt], outputs=[next_story_output], concurrency_limit=250)
|
113 |
|
114 |
edone_button.click(edone_story, inputs=[output_story, edited_story], outputs=[output_story], concurrency_limit=550)
|
115 |
|
116 |
ndone_button.click(ndone_story, inputs=[output_story, next_story_output], outputs=[output_story], concurrency_limit=550)
|
117 |
|
118 |
-
demo.launch(show_api=False, share=False)
|
|
|
53 |
except Exception as e:
|
54 |
return f"Ошибка редактирования: {e}"
|
55 |
|
56 |
+
def next_story_func(original_story="", next_prompt="", continuation_type="Продолжение"):
|
57 |
if original_story == "":
|
58 |
return f"Сначала сгенерируйте историю!"
|
59 |
|
60 |
try:
|
61 |
client = InferenceClient(api_key=get_random_api_key())
|
62 |
+
if continuation_type == "Продолжение следует...":
|
63 |
+
continuation_prompt = "Продолжи, подведя к тому, что продолжение следует."
|
64 |
+
elif continuation_type == "Концовка":
|
65 |
+
continuation_prompt = "Подведи к концовке истории."
|
66 |
+
else:
|
67 |
+
continuation_prompt = next_prompt
|
68 |
+
|
69 |
messages = [
|
70 |
{"role": "system", "content": "Продли историю, учитывая предоставленные указания. Продливай В ТОЧНОСТИ С КОНЦА, прям с того же символа, слова, предложения. (В начале добавляй новые строки/пробел если надо для отступа)"},
|
71 |
+
{"role": "user", "content": continuation_prompt},
|
72 |
{"role": "assistant", "content": original_story}
|
73 |
]
|
74 |
completion = client.chat.completions.create(model="Qwen/Qwen2.5-Coder-32B-Instruct", messages=messages, temperature=0.7, max_tokens=1000)
|
|
|
109 |
edone_button = gr.Button("Принять")
|
110 |
|
111 |
with gr.Tab("Продление"):
|
112 |
+
continuation_type = gr.Radio(choices=["Продолжение", "Продолжение следует...", "Концовка"], label="Выберите тип продолжения", value="Продолжение")
|
113 |
next_prompt = gr.Textbox(label="Введите изменения для продления истории (Необязательно)", placeholder="Продолжи, но что бы было...", lines=5)
|
114 |
next_button = gr.Button("Продлить", variant='primary')
|
115 |
next_story_output = gr.Textbox(label="Продолжение истории", lines=10, placeholder="Здесь будет продолжение вашей истории!")
|
|
|
117 |
|
118 |
generate_button.click(generate_story, inputs=[prompt, style], outputs=[output_story], concurrency_limit=250)
|
119 |
edit_button.click(edit_story, inputs=[output_story, edited_prompt], outputs=[edited_story], concurrency_limit=250)
|
120 |
+
next_button.click(next_story_func, inputs=[output_story, next_prompt, continuation_type], outputs=[next_story_output], concurrency_limit=250)
|
121 |
|
122 |
edone_button.click(edone_story, inputs=[output_story, edited_story], outputs=[output_story], concurrency_limit=550)
|
123 |
|
124 |
ndone_button.click(ndone_story, inputs=[output_story, next_story_output], outputs=[output_story], concurrency_limit=550)
|
125 |
|
126 |
+
demo.launch(show_api=False, share=False)
|