Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ from deep_translator import GoogleTranslator
|
|
| 5 |
from langdetect import detect
|
| 6 |
from huggingface_hub import InferenceClient
|
| 7 |
import gradio as gr
|
| 8 |
-
import inspect
|
| 9 |
|
| 10 |
def get_random_api_key():
|
| 11 |
keys = os.getenv("KEYS", "").split(",")
|
|
@@ -14,7 +13,6 @@ def get_random_api_key():
|
|
| 14 |
else:
|
| 15 |
raise ValueError("API keys not found. Please set the KEYS environment variable.")
|
| 16 |
|
| 17 |
-
|
| 18 |
css_url = "https://neurixyufi-aihub.static.hf.space/style.css"
|
| 19 |
try:
|
| 20 |
response = requests.get(css_url)
|
|
@@ -24,7 +22,6 @@ except requests.exceptions.RequestException as e:
|
|
| 24 |
print(f"Ошибка загрузки CSS: {e}")
|
| 25 |
css = " h1{text-align:center} .container { max-width: 800px; margin: 0 auto; }"
|
| 26 |
|
| 27 |
-
|
| 28 |
def generate_story(prompt, style):
|
| 29 |
try:
|
| 30 |
client = InferenceClient(api_key=get_random_api_key())
|
|
@@ -43,8 +40,6 @@ def generate_story(prompt, style):
|
|
| 43 |
except Exception as e:
|
| 44 |
return f"Ошибка генерации: {e}"
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
def edit_story(original_story, edited_prompt):
|
| 49 |
try:
|
| 50 |
client = InferenceClient(api_key=get_random_api_key())
|
|
@@ -59,8 +54,7 @@ def edit_story(original_story, edited_prompt):
|
|
| 59 |
except Exception as e:
|
| 60 |
return f"Ошибка редактирования: {e}"
|
| 61 |
|
| 62 |
-
|
| 63 |
-
def next_story(original_story, next_prompt):
|
| 64 |
try:
|
| 65 |
client = InferenceClient(api_key=get_random_api_key())
|
| 66 |
messages = [
|
|
@@ -74,8 +68,6 @@ def next_story(original_story, next_prompt):
|
|
| 74 |
except Exception as e:
|
| 75 |
return f"Ошибка продления: {e}"
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
with gr.Blocks(css=css) as demo:
|
| 80 |
with gr.Row():
|
| 81 |
style_choices = ["Приключенческая", "Научно-фантастическая", "Романтическая", "Комедийная", "Трагическая", "Введите свой стиль:"]
|
|
@@ -94,11 +86,11 @@ with gr.Blocks(css=css) as demo:
|
|
| 94 |
|
| 95 |
with gr.Tab("Продление"):
|
| 96 |
next_prompt = gr.Textbox(label="Введите изменения для продления истории", placeholder="Например: Продолжи историю", lines=5)
|
| 97 |
-
|
| 98 |
next_button = gr.Button("Продлить", variant='primary')
|
| 99 |
|
| 100 |
-
generate_button.click(generate_story, inputs=[prompt, style], outputs=[output_story],
|
| 101 |
-
edit_button.click(edit_story, inputs=[output_story, edited_prompt], outputs=[edited_story],
|
| 102 |
-
next_button.click(
|
| 103 |
|
| 104 |
demo.launch(show_api=False, share=False)
|
|
|
|
| 5 |
from langdetect import detect
|
| 6 |
from huggingface_hub import InferenceClient
|
| 7 |
import gradio as gr
|
|
|
|
| 8 |
|
| 9 |
def get_random_api_key():
|
| 10 |
keys = os.getenv("KEYS", "").split(",")
|
|
|
|
| 13 |
else:
|
| 14 |
raise ValueError("API keys not found. Please set the KEYS environment variable.")
|
| 15 |
|
|
|
|
| 16 |
css_url = "https://neurixyufi-aihub.static.hf.space/style.css"
|
| 17 |
try:
|
| 18 |
response = requests.get(css_url)
|
|
|
|
| 22 |
print(f"Ошибка загрузки CSS: {e}")
|
| 23 |
css = " h1{text-align:center} .container { max-width: 800px; margin: 0 auto; }"
|
| 24 |
|
|
|
|
| 25 |
def generate_story(prompt, style):
|
| 26 |
try:
|
| 27 |
client = InferenceClient(api_key=get_random_api_key())
|
|
|
|
| 40 |
except Exception as e:
|
| 41 |
return f"Ошибка генерации: {e}"
|
| 42 |
|
|
|
|
|
|
|
| 43 |
def edit_story(original_story, edited_prompt):
|
| 44 |
try:
|
| 45 |
client = InferenceClient(api_key=get_random_api_key())
|
|
|
|
| 54 |
except Exception as e:
|
| 55 |
return f"Ошибка редактирования: {e}"
|
| 56 |
|
| 57 |
+
def next_story_func(original_story, next_prompt):
|
|
|
|
| 58 |
try:
|
| 59 |
client = InferenceClient(api_key=get_random_api_key())
|
| 60 |
messages = [
|
|
|
|
| 68 |
except Exception as e:
|
| 69 |
return f"Ошибка продления: {e}"
|
| 70 |
|
|
|
|
|
|
|
| 71 |
with gr.Blocks(css=css) as demo:
|
| 72 |
with gr.Row():
|
| 73 |
style_choices = ["Приключенческая", "Научно-фантастическая", "Романтическая", "Комедийная", "Трагическая", "Введите свой стиль:"]
|
|
|
|
| 86 |
|
| 87 |
with gr.Tab("Продление"):
|
| 88 |
next_prompt = gr.Textbox(label="Введите изменения для продления истории", placeholder="Например: Продолжи историю", lines=5)
|
| 89 |
+
next_story_output = gr.Textbox(label="Продолжение истории", lines=10)
|
| 90 |
next_button = gr.Button("Продлить", variant='primary')
|
| 91 |
|
| 92 |
+
generate_button.click(generate_story, inputs=[prompt, style], outputs=[output_story], concurrency_limit=250)
|
| 93 |
+
edit_button.click(edit_story, inputs=[output_story, edited_prompt], outputs=[edited_story], concurrency_limit=250)
|
| 94 |
+
next_button.click(next_story_func, inputs=[output_story, next_prompt], outputs=[next_story_output], concurrency_limit=250)
|
| 95 |
|
| 96 |
demo.launch(show_api=False, share=False)
|