Rooni commited on
Commit
f643627
·
verified ·
1 Parent(s): 2c0b5a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -39,7 +39,7 @@ def generate_story(prompt, style):
39
  {"role": "user", "content": prompt}
40
  ]
41
 
42
- completion = client.chat.completions.create(model="Qwen/Qwen2.5-Coder-32B-Instruct", messages=messages, max_tokens=1000)
43
  story = completion.choices[0].message.content
44
  return story
45
  except Exception as e:
@@ -56,7 +56,23 @@ def edit_story(original_story, edited_prompt):
56
  {"role": "assistant", "content": original_story}
57
  ]
58
 
59
- completion = client.chat.completions.create(model="Qwen/Qwen2.5-Coder-32B-Instruct", messages=messages, max_tokens=1000)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  edited_story = completion.choices[0].message.content
61
  return edited_story
62
  except Exception as e:
@@ -79,7 +95,13 @@ with gr.Blocks(css=css) as demo:
79
  edited_story = gr.Textbox(label="Отредактированная история", lines=10)
80
  edit_button = gr.Button("Отредактировать", variant='primary')
81
 
 
 
 
 
 
82
  generate_button.click(generate_story, inputs=[prompt, style], outputs=[output_story], concurrency_limit=250)
83
  edit_button.click(edit_story, inputs=[output_story, edited_prompt], outputs=[edited_story], concurrency_limit=250)
 
84
 
85
  demo.launch(show_api=False, share=False)
 
39
  {"role": "user", "content": prompt}
40
  ]
41
 
42
+ completion = client.chat.completions.create(model="Qwen/Qwen2.5-Coder-32B-Instruct", messages=messages, temperature=0.7, max_tokens=1000)
43
  story = completion.choices[0].message.content
44
  return story
45
  except Exception as e:
 
56
  {"role": "assistant", "content": original_story}
57
  ]
58
 
59
+ completion = client.chat.completions.create(model="Qwen/Qwen2.5-Coder-32B-Instruct", messages=messages, temperature=0.7, max_tokens=1000)
60
+ edited_story = completion.choices[0].message.content
61
+ return edited_story
62
+ except Exception as e:
63
+ return f"Ошибка редактирования: {e}"
64
+
65
+ def next_story(original_story, edited_prompt=""):
66
+ try:
67
+ client = InferenceClient(api_key=get_random_api_key())
68
+
69
+ messages = [
70
+ {"role": "system", "content": "Продли историю, учитывая предоставленные указания. Продливай В ТОЧНОСТИ С КОНЦА, прям с того же символа, слова, предложения."},
71
+ {"role": "user", "content": edited_prompt},
72
+ {"role": "assistant", "content": original_story}
73
+ ]
74
+
75
+ completion = client.chat.completions.create(model="Qwen/Qwen2.5-Coder-32B-Instruct", messages=messages, temperature=0.7, max_tokens=2500)
76
  edited_story = completion.choices[0].message.content
77
  return edited_story
78
  except Exception as e:
 
95
  edited_story = gr.Textbox(label="Отредактированная история", lines=10)
96
  edit_button = gr.Button("Отредактировать", variant='primary')
97
 
98
+ with gr.Tab("Продление"):
99
+ next_prompt = gr.Textbox(label="Введите изменения для истории", placeholder="Например: Сделай историю более захватывающей", lines=5)
100
+ next_story = gr.Textbox(label="Отредактированная история", lines=10)
101
+ next_button = gr.Button("Продлить", variant='primary')
102
+
103
  generate_button.click(generate_story, inputs=[prompt, style], outputs=[output_story], concurrency_limit=250)
104
  edit_button.click(edit_story, inputs=[output_story, edited_prompt], outputs=[edited_story], concurrency_limit=250)
105
+ next_button.click(next_story, inputs=[output_story, next_prompt], outputs=[next_story], concurrency_limit=250)
106
 
107
  demo.launch(show_api=False, share=False)