Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from Promptless_LLM_Agent import questions
|
| 2 |
+
from Summarization import Summarizer
|
| 3 |
+
from TextToImage_StableDiffusion import generate as image_generator
|
| 4 |
+
|
| 5 |
+
import random
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
user_defined_questions = ["What is the title or subject of the video? Please provide a brief description (1-2 sentences) to help me understand the content?",
|
| 12 |
+
"What type of video is this (e.g., documentary, informative, sarcastic, comedy, tutorial, review, etc.)?",
|
| 13 |
+
"Are there any specific keywords or tags you want to include for search optimization? ",
|
| 14 |
+
"What is the desired mood or atmosphere for the thumbnail (e.g., energetic, calm, inspirational, humorous)?",
|
| 15 |
+
"What style or tone do you want to convey (e.g., serious, playful, minimalist, detailed)?",
|
| 16 |
+
"Are there any specific text elements (e.g., titles, subtitles, quotes) you want to include in the thumbnail?",
|
| 17 |
+
"Who is the target audience for this video?"
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
def nextGen():
|
| 21 |
+
try:
|
| 22 |
+
x = next(q)
|
| 23 |
+
except StopIteration:
|
| 24 |
+
x = None
|
| 25 |
+
return x
|
| 26 |
+
|
| 27 |
+
def requirement_string(req, QA):
|
| 28 |
+
req = "User Requirement: "+req+"\n"
|
| 29 |
+
for q, a in QA:
|
| 30 |
+
req = req+'\n'+'Graphic Designer: '+q+'\n'+'User: '+a
|
| 31 |
+
return req
|
| 32 |
+
|
| 33 |
+
r = None
|
| 34 |
+
q = None
|
| 35 |
+
qa = None
|
| 36 |
+
summary = None
|
| 37 |
+
|
| 38 |
+
with gr.Blocks() as demo:
|
| 39 |
+
|
| 40 |
+
title = gr.Label(value="Graphic Designer", show_label=False)
|
| 41 |
+
|
| 42 |
+
a = gr.Textbox(label="Enter Requirement")
|
| 43 |
+
b = gr.Button("Submit")
|
| 44 |
+
c = gr.Label(visible=False)
|
| 45 |
+
d = gr.Chatbot(visible=False, layout='bubble', rtl=False)
|
| 46 |
+
g = gr.Textbox(visible=False)
|
| 47 |
+
e = gr.Textbox(visible=False)
|
| 48 |
+
|
| 49 |
+
with gr.Row():
|
| 50 |
+
with gr.Column():
|
| 51 |
+
n = gr.Button(visible=False)
|
| 52 |
+
with gr.Column():
|
| 53 |
+
f = gr.Button(visible=False)
|
| 54 |
+
|
| 55 |
+
h = gr.Label(visible=False)
|
| 56 |
+
m = gr.Image(visible=False)
|
| 57 |
+
|
| 58 |
+
def fn_req(data):
|
| 59 |
+
global r
|
| 60 |
+
global q
|
| 61 |
+
r = data[a]
|
| 62 |
+
|
| 63 |
+
if data[a].endswith("/generate"):
|
| 64 |
+
summary = data[a].replace("/generate","")
|
| 65 |
+
image = image_generator(summary)
|
| 66 |
+
return {a: gr.Textbox(visible=False),
|
| 67 |
+
b: gr.Button(visible=False),
|
| 68 |
+
c: gr.Label(value=summary, label="Customer Requirement", visible=True),
|
| 69 |
+
m: gr.Image(value=image ,visible=True)}
|
| 70 |
+
|
| 71 |
+
try:
|
| 72 |
+
llm_q = questions(data[a])
|
| 73 |
+
llm_q = random.sample(llm_q, 3)
|
| 74 |
+
except:
|
| 75 |
+
llm_q = []
|
| 76 |
+
|
| 77 |
+
all_q = user_defined_questions + llm_q
|
| 78 |
+
q = (i for i in all_q[:3])
|
| 79 |
+
# q = (i for i in questions(data[a])[:3])
|
| 80 |
+
return {a: gr.Textbox(visible=False),
|
| 81 |
+
b: gr.Button(visible=False),
|
| 82 |
+
c: gr.Label(value=data[a], label="Customer Requirement", visible=True),
|
| 83 |
+
d: gr.Chatbot(label="Requirements Gathering", visible=True),
|
| 84 |
+
g: gr.Textbox(value=nextGen(), label="Question", visible=True),
|
| 85 |
+
e: gr.Textbox(label="Answer", visible=True),
|
| 86 |
+
n: gr.Button("Skip Question", visible=True),
|
| 87 |
+
f: gr.Button("Submit Answer", visible=True)}
|
| 88 |
+
|
| 89 |
+
def bot_user_response(question, answer, history):
|
| 90 |
+
global qa
|
| 91 |
+
global summary
|
| 92 |
+
if answer:
|
| 93 |
+
history = history + [[question, answer]]
|
| 94 |
+
question = nextGen()
|
| 95 |
+
|
| 96 |
+
if question:
|
| 97 |
+
return {g: question, e: '', d: history}
|
| 98 |
+
else:
|
| 99 |
+
qa = requirement_string(r, history)
|
| 100 |
+
summary = Summarizer(qa)
|
| 101 |
+
# summary = """The user requires a YouTube thumbnail for an educational video.
|
| 102 |
+
# They want a dancer to be featured in the image and
|
| 103 |
+
# the tone or mood they want to convey is joyful."""
|
| 104 |
+
image = image_generator(summary)
|
| 105 |
+
text = "Thank you for your response"
|
| 106 |
+
return {g: gr.Textbox(visible=False),
|
| 107 |
+
e: gr.Textbox(visible=False),
|
| 108 |
+
d: history,
|
| 109 |
+
h: gr.Label(value=text, visible=True, show_label=False),
|
| 110 |
+
n: gr.Button(visible=False),
|
| 111 |
+
f: gr.Button(visible=False),
|
| 112 |
+
m: gr.Image(value=image ,visible=True)}
|
| 113 |
+
|
| 114 |
+
b.click(fn=fn_req, inputs={a}, outputs=[a,b,c,d,g,e,n,f,m])
|
| 115 |
+
|
| 116 |
+
f.click(bot_user_response, [g, e, d], [g, e, d, h, n, f, m])
|
| 117 |
+
n.click(bot_user_response, [g, e, d], [g, e, d, h, n, f, m])
|
| 118 |
+
|
| 119 |
+
demo.launch()
|
| 120 |
+
|