Create app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677import gradio as gr
def graphic_design_chatbot(user_message, history): if history is None: history = [] user_message_lower = user_message.lower()
# Basic keyword-based recommendations for demonstration if any(word in user_message_lower for word in ["logo", "branding"]): response = ( "For logo and branding design, consider using vector graphics software like Adobe Illustrator " "or the free alternative Inkscape. Keep your design simple, memorable, and versatile." ) elif any(word in user_message_lower for word in ["color", "palette", "colors"]): response = ( "Choosing the right color palette is crucial. Tools like Coolors.co or Adobe Color can help you " "create harmonizing color schemes based on color theory principles." ) elif any(word in user_message_lower for word in ["font", "typography"]): response = ( "Typography sets the tone of your design. Google Fonts offers a wide range of modern and free typefaces. " "Pay attention to line spacing and contrast for readability." ) elif any(word in user_message_lower for word in ["layout", "composition", "grid"]): response = ( "A solid grid and layout structure organizes content visually. Use tools like Figma or Adobe XD to experiment " "with layouts. Remember principles like alignment, proximity, and balance." ) elif any(word in user_message_lower for word in ["software", "tool", "tools"]): response = ( "Popular graphic design software includes Adobe Photoshop, Illustrator, Figma, Sketch (Mac only), and Affinity Designer. " "Choose based on your workflow and platform." ) elif any(word in user_message_lower for word in ["trends", "inspiration"]): response = ( "Stay updated with current design trends by exploring sites like Dribbble, Behance, and Awwwards. " "They provide great inspiration from professional designers." ) else: response = ( "I'm specialized in graphic design advice. Try asking me about logo creation, color choices, typography, " "or design tools!" )
history.append((user_message, response)) return history, history
with gr.Blocks(title="Graphic Design Recommendation Chatbot") as demo: gr.Markdown( """ # 🎨 Graphic Design Recommendation Chatbot Ask me anything about graphic design, from tools to best practices! """, elem_id="header", ) chatbot = gr.Chatbot(elem_id="chatbot").style(height=400) user_input = gr.Textbox( placeholder="Type your question about graphic design here...", show_label=False, elem_id="user_input", ) state = gr.State([])
def user_submit(user_message, history): return graphic_design_chatbot(user_message, history)
user_input.submit(user_submit, inputs=[user_input, state], outputs=[chatbot, state]) user_input.submit(lambda: "", None, user_input) # Clear user input after submitting
# Also allow a "Send" button for accessibility send_button = gr.Button("Send") send_button.click(user_submit, inputs=[user_input, state], outputs=[chatbot, state]) send_button.click(lambda: "", None, user_input)
if __name__ == "__main__": demo.queue().launch()
app.pyAdded+77