kevinhug commited on
Commit
8361559
·
1 Parent(s): 8e73b66
Files changed (2) hide show
  1. app.py +6 -3
  2. graphrag.py +26 -0
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  from rag import rbc_product
3
  from tool import rival_product
4
- from graphrag import reasoning
5
  from knowledge import graph
6
  from pii import derisk
7
  from classify import judge
@@ -48,6 +48,10 @@ Other Links:
48
  ================================================
49
  - Retrieval: Public RBC Product Data
50
  - Recommend: RBC Product
 
 
 
 
51
  """)
52
  in_verbatim = gr.Textbox(label="Verbatim")
53
  out_product = gr.Textbox(label="Product")
@@ -158,14 +162,13 @@ By framing each component as a strategic variable rather than a fixed element, b
158
  [
159
  [
160
  """
161
- Create marketing campaign that can improve customer acquisition, activation, retention and referral for this persona:
162
  Low APR and great customer service. I would highly recommend if you’re looking for a great credit card company and looking to rebuild your credit. I have had my credit limit increased annually and the annual fee is very low.
163
  """]
164
  ],
165
  [in_question]
166
  )
167
  btn_recommend = gr.Button("Reasoning")
168
- btn_recommend.click(fn=reasoning, inputs=[in_verbatim, in_question], outputs=out_product)
169
 
170
  gr.Markdown("""
171
  Benefits of a Marketing Campaign Generator
 
1
  import gradio as gr
2
  from rag import rbc_product
3
  from tool import rival_product
4
+ from graphrag import marketing
5
  from knowledge import graph
6
  from pii import derisk
7
  from classify import judge
 
48
  ================================================
49
  - Retrieval: Public RBC Product Data
50
  - Recommend: RBC Product
51
+
52
+ Potential Optimization
53
+ ------------
54
+ BM25 reranking using keyword
55
  """)
56
  in_verbatim = gr.Textbox(label="Verbatim")
57
  out_product = gr.Textbox(label="Product")
 
162
  [
163
  [
164
  """
 
165
  Low APR and great customer service. I would highly recommend if you’re looking for a great credit card company and looking to rebuild your credit. I have had my credit limit increased annually and the annual fee is very low.
166
  """]
167
  ],
168
  [in_question]
169
  )
170
  btn_recommend = gr.Button("Reasoning")
171
+ btn_recommend.click(fn=marketing, inputs=[in_verbatim, in_question], outputs=out_product)
172
 
173
  gr.Markdown("""
174
  Benefits of a Marketing Campaign Generator
graphrag.py CHANGED
@@ -89,3 +89,29 @@ def reasoning(text, question):
89
  traceback.print_exc()
90
  return str(e)
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  traceback.print_exc()
90
  return str(e)
91
 
92
+
93
+ def marketing(text, question):
94
+ try:
95
+ print("Generate Knowledgegraph...")
96
+ graph, graph_documents_filtered = knowledge_graph(f"""Create
97
+ marketing campaign that can improve customer acquisition, activation, retention and referral for this persona: {text}""")
98
+
99
+ print("GraphQAChain...")
100
+ graph_rag = GraphQAChain.from_llm(
101
+ llm=llm,
102
+ graph=graph,
103
+ verbose=True
104
+ )
105
+
106
+ print("Answering through GraphQAChain...")
107
+ answer = graph_rag.invoke(question)
108
+ return answer['result']
109
+
110
+ except Exception as e:
111
+ print(f"An error occurred in process_text: {str(e)}")
112
+ import traceback
113
+ traceback.print_exc()
114
+ return str(e)
115
+
116
+ if __name__=="__main__":
117
+ pass