Spaces:
Sleeping
Sleeping
File size: 7,213 Bytes
79a4761 87e6555 79a4761 87e6555 b8a8747 87e6555 b8a8747 87e6555 b8a8747 87e6555 b8a8747 87e6555 b8a8747 87e6555 b8a8747 87e6555 b8a8747 87e6555 79a4761 87e6555 79a4761 b8a8747 79a4761 | 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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | # 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()
|