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