jehanzada commited on
Commit
6ff7a33
·
verified ·
1 Parent(s): f23f753

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -13,7 +13,7 @@ GROQ_API_KEY = os.getenv("Freelancing_key")
13
  client = Groq(api_key=GROQ_API_KEY)
14
 
15
  # ===============================
16
- # AI RESPONSE FUNCTION
17
  # ===============================
18
 
19
  def generate_response(task, user_input, tone, history):
@@ -22,19 +22,18 @@ def generate_response(task, user_input, tone, history):
22
  history = []
23
 
24
  prompt = f"""
25
- Task: {task}
26
- Tone: {tone}
27
- User Request: {user_input}
28
- """
29
 
30
  messages = [
31
  {"role": "system", "content": "You are a professional AI business assistant."}
32
  ]
33
 
34
  # Add previous chat correctly
35
- for user_msg, bot_msg in history:
36
- messages.append({"role": "user", "content": user_msg})
37
- messages.append({"role": "assistant", "content": bot_msg})
38
 
39
  messages.append({"role": "user", "content": prompt})
40
 
@@ -46,7 +45,9 @@ def generate_response(task, user_input, tone, history):
46
 
47
  answer = response.choices[0].message.content
48
 
49
- history.append((user_input, answer))
 
 
50
 
51
  return history, history
52
 
@@ -62,25 +63,25 @@ def download_pdf(history):
62
  elements = []
63
  styles = getSampleStyleSheet()
64
 
65
- for user_msg, bot_msg in history:
66
- elements.append(Paragraph(f"<b>User:</b> {user_msg}", styles["Normal"]))
67
- elements.append(Spacer(1, 0.3 * inch))
68
- elements.append(Paragraph(f"<b>AI:</b> {bot_msg}", styles["Normal"]))
69
- elements.append(Spacer(1, 0.5 * inch))
70
 
71
  doc.build(elements)
72
  return file_path
73
 
74
 
75
  # ===============================
76
- # GRADIO UI (Compatible Version)
77
  # ===============================
78
 
79
  with gr.Blocks() as demo:
80
 
81
  gr.Markdown("# 💰 Freelancing AI Agent Pro")
82
 
83
- chatbot = gr.Chatbot() # NO type="messages"
84
  state = gr.State([])
85
 
86
  task = gr.Dropdown(
 
13
  client = Groq(api_key=GROQ_API_KEY)
14
 
15
  # ===============================
16
+ # AI RESPONSE FUNCTION (NEW FORMAT)
17
  # ===============================
18
 
19
  def generate_response(task, user_input, tone, history):
 
22
  history = []
23
 
24
  prompt = f"""
25
+ Task: {task}
26
+ Tone: {tone}
27
+ User Request: {user_input}
28
+ """
29
 
30
  messages = [
31
  {"role": "system", "content": "You are a professional AI business assistant."}
32
  ]
33
 
34
  # Add previous chat correctly
35
+ for message in history:
36
+ messages.append(message)
 
37
 
38
  messages.append({"role": "user", "content": prompt})
39
 
 
45
 
46
  answer = response.choices[0].message.content
47
 
48
+ # Append in NEW format
49
+ history.append({"role": "user", "content": user_input})
50
+ history.append({"role": "assistant", "content": answer})
51
 
52
  return history, history
53
 
 
63
  elements = []
64
  styles = getSampleStyleSheet()
65
 
66
+ for message in history:
67
+ role = message["role"]
68
+ content = message["content"]
69
+ elements.append(Paragraph(f"<b>{role.capitalize()}:</b> {content}", styles["Normal"]))
70
+ elements.append(Spacer(1, 0.4 * inch))
71
 
72
  doc.build(elements)
73
  return file_path
74
 
75
 
76
  # ===============================
77
+ # GRADIO UI (NEW FORMAT)
78
  # ===============================
79
 
80
  with gr.Blocks() as demo:
81
 
82
  gr.Markdown("# 💰 Freelancing AI Agent Pro")
83
 
84
+ chatbot = gr.Chatbot() # NEW version auto-detects message format
85
  state = gr.State([])
86
 
87
  task = gr.Dropdown(