Commit
·
1cd99ec
1
Parent(s):
43e6e5d
fetch order details
Browse files- app.py +23 -14
- gemini_api.py +8 -2
app.py
CHANGED
@@ -1,15 +1,14 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
from gemini_api import model_api, sentiment, category, ord_num
|
4 |
|
5 |
cust_qry_resp = {"senti":"", "cat":"", "num":""}
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
#********* UI Code ***********#
|
11 |
with gr.Blocks(title="Customer Support Assistant",
|
12 |
analytics_enabled=False) as app:
|
|
|
13 |
gr.Markdown("Customer Support Assistant")
|
14 |
# Inputs from user
|
15 |
with gr.Row():
|
@@ -28,17 +27,27 @@ with gr.Blocks(title="Customer Support Assistant",
|
|
28 |
cat = model_api(user_input, category)
|
29 |
num = model_api(user_input, ord_num)
|
30 |
# Output response
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
if num != "Order Number not provided.":
|
38 |
btn_ord_det = gr.Button("Fetch Order Details")
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
app.launch(server_name="0.0.0.0")
|
|
|
1 |
import gradio as gr
|
2 |
+
from datetime import datetime, timedelta
|
3 |
|
4 |
+
from gemini_api import model_api, sentiment, category, ord_num, NO_ORDER
|
5 |
|
6 |
cust_qry_resp = {"senti":"", "cat":"", "num":""}
|
7 |
|
|
|
|
|
|
|
8 |
#********* UI Code ***********#
|
9 |
with gr.Blocks(title="Customer Support Assistant",
|
10 |
analytics_enabled=False) as app:
|
11 |
+
state_order_num = gr.State(NO_ORDER)
|
12 |
gr.Markdown("Customer Support Assistant")
|
13 |
# Inputs from user
|
14 |
with gr.Row():
|
|
|
27 |
cat = model_api(user_input, category)
|
28 |
num = model_api(user_input, ord_num)
|
29 |
# Output response
|
30 |
+
gr.Textbox(lines=1, type="text", label="Customer Sentiment", value=senti)
|
31 |
+
gr.Textbox(lines=1, type="text", label="Order Category", value=cat)
|
32 |
+
gr.Textbox(lines=1, type="text", label="Order Number", value=num)
|
33 |
+
|
34 |
+
# Decision Rules
|
35 |
+
if num != NO_ORDER:
|
|
|
36 |
btn_ord_det = gr.Button("Fetch Order Details")
|
37 |
+
btn_ord_det.click(lambda x: num, state_order_num, state_order_num)
|
38 |
+
# Order Details
|
39 |
+
if senti == "NEGATIVE" and num == NO_ORDER:
|
40 |
+
with gr.Row():
|
41 |
+
gr.Textbox(lines=1, type="text", label="Next Step", value="Ask Order Number")
|
42 |
+
|
43 |
+
@gr.render(inputs=state_order_num)
|
44 |
+
def fetch_order_det(ord_num):
|
45 |
+
print("Get order Details")
|
46 |
+
if ord_num != NO_ORDER:
|
47 |
+
pur_dt = datetime.now() + timedelta(days=-2)
|
48 |
+
ord_det = f"Order Number: {ord_num}\nPurchase Date: {pur_dt}"
|
49 |
+
gr.Textbox(lines=1, type="text", label="Order Details", value=ord_det)
|
50 |
+
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
app.launch(server_name="0.0.0.0")
|
gemini_api.py
CHANGED
@@ -2,7 +2,8 @@ import google.generativeai as genai
|
|
2 |
import json
|
3 |
import os
|
4 |
|
5 |
-
genai.configure(api_key=
|
|
|
6 |
generation_config = {
|
7 |
"temperature": 0.9,
|
8 |
"top_p": 1,
|
@@ -34,6 +35,7 @@ model = genai.GenerativeModel(
|
|
34 |
safety_settings=safety_settings,
|
35 |
generation_config=generation_config,
|
36 |
)
|
|
|
37 |
|
38 |
def model_api(input, prompt_type):
|
39 |
return prompt_type(input)
|
@@ -90,5 +92,9 @@ def ord_num(input):
|
|
90 |
|
91 |
print(response.text)
|
92 |
obj = json.loads(response.text)
|
93 |
-
|
|
|
|
|
|
|
|
|
94 |
|
|
|
2 |
import json
|
3 |
import os
|
4 |
|
5 |
+
genai.configure(api_key="AIzaSyAT-eqTQUIpoVpmM-PL5hR5el1n6YqZRV4")
|
6 |
+
# genai.configure(api_key=os.getenv("API_KEY"))
|
7 |
generation_config = {
|
8 |
"temperature": 0.9,
|
9 |
"top_p": 1,
|
|
|
35 |
safety_settings=safety_settings,
|
36 |
generation_config=generation_config,
|
37 |
)
|
38 |
+
NO_ORDER = "Order Number not provided."
|
39 |
|
40 |
def model_api(input, prompt_type):
|
41 |
return prompt_type(input)
|
|
|
92 |
|
93 |
print(response.text)
|
94 |
obj = json.loads(response.text)
|
95 |
+
ret_num = obj.get('order number', NO_ORDER)
|
96 |
+
if ret_num is None:
|
97 |
+
return NO_ORDER
|
98 |
+
else:
|
99 |
+
return ret_num
|
100 |
|