Spaces:
Sleeping
Sleeping
| 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() | |