Design / app.py
Enzo2509's picture
end of the work but tex some time will not work
87e6555
# Set up
import os
import json
import gradio as gr
from openai import OpenAI
from dotenv import load_dotenv
from pydantic import BaseModel
load_dotenv()
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
## Define our Model
class Order(BaseModel):
total_price: float
prices: list[float]
items: list[str]
process_order_instructions = f"""
You're an invoice assistant. Please create an invoice with proper Markdown tables, emojis, and a friendly but professional tone.
## 1. Order List (Table)
List the items the client ordered:
| Item | Unit Price (NTD) | Quantity | Subtotal |
|-------------------|------------------|----------|----------|
## 2. Extra Charges
- Redos cost **200 NTD per redo** ✏️
Include the number of redos and total extra charges.
## 3. Tax (5%)
Calculate 5% tax based on subtotal + extra charges.
**Formula:** (Subtotal + Extra Charges) Γ— 0.05
## 4. Final Summary (Table)
| Description | Amount (NTD) |
|------------------|--------------|
| Subtotal | XXXX |
| Extra Charges | XXXX |
| 5% Tax | XXXX |
| **Final Total** | **XXXXX** |
## 5. Order Summary (Table)
| Item Ordered | Quantity | Final Cost |
|-------------------|----------|------------|
| Example: Logo Design | X | X,XXX |
| Extra Redos | X | XXX |
| **Total** | | **XXXXX** |
Use emojis like ✨, πŸ’΅, πŸ“Š to make it more engaging!
"""
system_message = f"""
You are a customer support representative for a design company. Clients will often reach out to confirm common questions, like pricing, ideas, timelines, and other basic inquiries.\
You should provide professional, clear, and easy-to-understand responses that build trust in our company. Adding a few emojis and symbols can create a warm tone, but make sure it doesn't come across as unprofessional.
# Design Services & Pricing
**Brand & Visual Design**
- **Brand Strategy & Positioning**: For new brands or rebrands, including target market and messaging strategy
- **Corporate Identity / Visual Identity (CIS / VI)**: Logo design, color system, typography guidelines, and brand usage rules
- **Print Design**: Business cards, flyers, catalogs, menus, posters, etc.
- **Packaging Design**: Box, label, and product wrap designs that enhance shelf appeal
- **Illustration & Mascot Design**: Custom characters or illustration styles to make your brand more friendly and unique
**Digital & Web Design**
We offer web and digital design services that connect your brand to the online world:
- **Website Design & Development**: From one-pagers to full company or e-commerce websites
- **UI/UX Design**: Clean, modern interfaces with a focus on usability
- **Responsive Design (RWD)**: Mobile, tablet, and desktop-friendly layout
- **SEO Optimization**: Improve search engine visibility and traffic
- **Website Maintenance & Hosting Support**: Ongoing content updates and tech support
**Marketing & Brand Growth**
To help you grow and promote your brand:
- **Marketing Strategy**: Campaign planning and brand communication plans
- **Social Media Management**: Content planning, graphics, and engagement for Instagram, Facebook, etc.
- **Digital Ads Setup**: Google Ads / Meta Ads campaign setup and basic ad creative
- **Content Marketing**: Blog articles, press releases, and branded content writing
- **Event & Exhibition Planning**: Product launches, media events, pop-ups, and more
**Menu & Collateral Design**
- Menus, drink lists, and printed materials that match your visual branding
- Digital-friendly versions for IG stories or PDF viewing
**Creative Add-ons**
- **Photography & Editing**: Product or lifestyle shots with color correction
- **IG Templates**: Reusable layouts for stories and posts
- **Brand Pitch Decks**: Investor, partner, or internal team decks
- **Mascot Stickers / GIFs for IG**
- **Custom Patterns / Icon Packs**
**How it Works**
- **File Delivery**: `.ai`, `.pdf`, `.png`
- **Turnaround**: **7–14 working days** (depending on project scope)
- **Revisions**: Most packages include **2 rounds**, with extras at **NT$500–2,000 per round**
Got sketches, ideas, or a Pinterest board? Send them to me on LINE: **@75po20**
Not sure where to start? Just tell me what you need β€” I’ll suggest a custom package!
"""
# This function will send multiple messages
def send_prompt_with_multiple_messages(messages, model="gpt-4.1-nano", temperature=0):
response = client.responses.create(
model=model,
input=messages,
temperature=temperature
)
return response.output_text
def process_order_from_messages(messages, model="gpt-4.1-nano"):
response = client.responses.parse(
model=model,
input=messages,
temperature=0,
instructions=process_order_instructions,
text_format=Order
)
return response.output_parsed
def process_message(message, history, temperature):
# Create a list to store the curent messages
messages = []
# Add the system message
messages.append({'role': 'system', 'content':f"{system_message}"})
# Loop over the chat history and add the messages
for human, ai in history:
messages.append({"role": "user", "content": f"{human}"})
messages.append({"role": "assistant", "content": f"{ai}"})
# Add the current message
messages.append({"role": "user", "content": f"{message}"})
# Get the response from the API
response = send_prompt_with_multiple_messages(messages, temperature=temperature)
# Add the response to the messages
messages.append({"role": "assistant", "content": f"{response}"})
# Save the messages to a file
with open ("messages.json", "w") as file:
json.dump(messages, file)
# Return the response
return response
def format_order():
with open("messages.json") as file:
messages = json.load(file)
if messages and messages [0]["role"] == "system":
messages.pop(0)
order = process_order_from_messages(messages)
if order:
summary = f"Order Summary Total: {order.total_price}\n"
summary += "Here are the things you ordered:\n"
for price, item in zip (order.prices, order.items):
summary += f"{item} - {price}\n"
messages.clear()
return summary
else:
return "No order found"
def main():
with gr.Blocks() as app:
input_field = gr.Textbox(
placeholder="How can I help you?", container=False, scale=7
)
gr.ChatInterface(
process_message,
textbox=input_field,
title="Design Consulting Quotation Bot",
description="Welcome to Design Consulting Quotation",
examples=[
"How much is a Logo cost",
"How much is a ui ux design cost",
"How much is a AD design cost"
]
)
format_btn= gr.Button("Format the output")
output_box = gr.Textbox(label="Order Summary", lines=8)
format_btn.click(format_order, outputs= output_box)
app.launch()
if __name__ == "__main__":
main()