Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
pipe = pipeline('text-generation', model_id='Ar4ikov/gpt2-650k-stable-diffusion-prompt-generator')
|
5 |
+
|
6 |
+
def get_valid_prompt(text: str) -> str:
|
7 |
+
dot_split = text.split('.')[0]
|
8 |
+
n_split = text.split('\n')[0]
|
9 |
+
|
10 |
+
return {
|
11 |
+
len(dot_split) < len(n_split): dot_split,
|
12 |
+
len(n_split) > len(dot_split): n_split,
|
13 |
+
len(n_split) == len(dot_split): dot_split
|
14 |
+
}[True]
|
15 |
+
|
16 |
+
def generate_prompt(prompt):
|
17 |
+
valid_prompt = get_valid_prompt(pipe(prompt, max_length=77)[0]['generated_text'])
|
18 |
+
return valid_prompt
|
19 |
+
|
20 |
+
iface = gr.Interface(
|
21 |
+
fn=generate_prompt,
|
22 |
+
inputs="text",
|
23 |
+
outputs="text",
|
24 |
+
title="Prompt Generator",
|
25 |
+
description="Enter a prompt and get the valid prompt generated by the script."
|
26 |
+
)
|
27 |
+
|
28 |
+
iface.launch()
|