debisoft commited on
Commit
07a2f32
1 Parent(s): f472456
Files changed (1) hide show
  1. app.py +42 -41
app.py CHANGED
@@ -10,7 +10,41 @@ _ = load_dotenv(find_dotenv())
10
 
11
  databricks_token = os.getenv('DATABRICKS_TOKEN')
12
  model_uri = "https://dbc-eb788f31-6c73.cloud.databricks.com/serving-endpoints/Mpt-7b-tester/invocations"
13
- n_shot_learning = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  ### Instruction:
16
  You are demanding customer
@@ -57,45 +91,7 @@ I am building an online community to help people to find dates.
57
  {{"solution": "FindDates.com", "problem": "finding a date", "features": "online community to help people find dates", "target_customer": "people looking for a date", "fg_will_use": "True", "reason_to_use": "I am looking for an online community to help people find dates. FindDates.com meets my needs and I would use it to find my next great date.","fg_will_pay": "True", "reason_to_pay": "I would not pay for it as I am looking for an online community to help people find dates. But for products related to dating, paying for it would be a no-brainer.","fg_will_invest": "False", "reason_to_invest": "There are many online dating platforms already.","score": "40"}}
58
  """
59
 
60
- def extract_json(gen_text, n_shot_learning=0):
61
- start_index = gen_text.index("### Response:\n{") + 14
62
- if(n_shot_learning > 0) :
63
- for i in range(0, n_shot_learning):
64
- gen_text = gen_text[start_index:]
65
- start_index = gen_text.index("### Response:\n{") + 14
66
- end_index = gen_text.index("}\n\n### ") + 1
67
- return gen_text[start_index:end_index]
68
-
69
- def score_model(model_uri, databricks_token, prompt):
70
- dataset=pd.DataFrame({
71
- "prompt":[prompt],
72
- "temperature": [0.5],
73
- "max_tokens": [1000]})
74
- headers = {
75
- "Authorization": f"Bearer {databricks_token}",
76
- "Content-Type": "application/json",
77
- }
78
- ds_dict = {'dataframe_split': dataset.to_dict(orient='split')} if isinstance(dataset, pd.DataFrame) else create_tf_serving_json(dataset)
79
- data_json = json.dumps(ds_dict, allow_nan=True)
80
- print("***ds_dict: ")
81
- print(ds_dict)
82
- print("***data_json: ")
83
- print(data_json)
84
- response = requests.request(method='POST', headers=headers, url=model_uri, data=data_json)
85
- if response.status_code != 200:
86
- raise Exception(f"Request failed with status {response.status_code}, {response.text}")
87
- return response.json()
88
-
89
- def get_completion(prompt):
90
- return score_model(model_uri, databricks_token, prompt)
91
- #def get_completion(prompt):
92
-
93
- def greet(company, solution, target_customer, problem, features, target_audience_persona="the target customer"):
94
- customer_persona = target_audience_persona
95
- pitch = f"""My company, {company} is developing {solution} to help {target_customer} {problem} with {features}"""
96
- input = pitch
97
-
98
- sys_msg=f"You are {customer_persona}."
99
 
100
  instruction = """Determine the product or solution, the problem being solved, features, target customer that are being discussed in the \
101
  following user prompt. State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.\
@@ -123,6 +119,11 @@ Give a score for the product. Format your response as a JSON object with \
123
  response = get_completion(total_prompt)
124
  gen_text = response["predictions"][0]["generated_text"]
125
  return json.dumps(extract_json(gen_text, 3))
 
 
 
 
126
 
127
- iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Company"), gr.Textbox(label="Solution"), gr.Textbox(label="Customer"), gr.Textbox(label="Problem"), gr.Textbox(label="Feature"), gr.Textbox(label="Target Audience persona", lines=3)], outputs="json")
 
128
  iface.launch()
 
10
 
11
  databricks_token = os.getenv('DATABRICKS_TOKEN')
12
  model_uri = "https://dbc-eb788f31-6c73.cloud.databricks.com/serving-endpoints/Mpt-7b-tester/invocations"
13
+
14
+ def extract_json(gen_text, n_shot_learning=0):
15
+ start_index = gen_text.index("### Response:\n{") + 14
16
+ if(n_shot_learning > 0) :
17
+ for i in range(0, n_shot_learning):
18
+ gen_text = gen_text[start_index:]
19
+ start_index = gen_text.index("### Response:\n{") + 14
20
+ end_index = gen_text.index("}\n\n### ") + 1
21
+ return gen_text[start_index:end_index]
22
+
23
+ def score_model(model_uri, databricks_token, prompt):
24
+ dataset=pd.DataFrame({
25
+ "prompt":[prompt],
26
+ "temperature": [0.5],
27
+ "max_tokens": [1000]})
28
+ headers = {
29
+ "Authorization": f"Bearer {databricks_token}",
30
+ "Content-Type": "application/json",
31
+ }
32
+ ds_dict = {'dataframe_split': dataset.to_dict(orient='split')} if isinstance(dataset, pd.DataFrame) else create_tf_serving_json(dataset)
33
+ data_json = json.dumps(ds_dict, allow_nan=True)
34
+ print("***ds_dict: ")
35
+ print(ds_dict)
36
+ print("***data_json: ")
37
+ print(data_json)
38
+ response = requests.request(method='POST', headers=headers, url=model_uri, data=data_json)
39
+ if response.status_code != 200:
40
+ raise Exception(f"Request failed with status {response.status_code}, {response.text}")
41
+ return response.json()
42
+
43
+ def get_completion(prompt):
44
+ return score_model(model_uri, databricks_token, prompt)
45
+
46
+ def greet(input):
47
+ n_shot_learning = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
48
 
49
  ### Instruction:
50
  You are demanding customer
 
91
  {{"solution": "FindDates.com", "problem": "finding a date", "features": "online community to help people find dates", "target_customer": "people looking for a date", "fg_will_use": "True", "reason_to_use": "I am looking for an online community to help people find dates. FindDates.com meets my needs and I would use it to find my next great date.","fg_will_pay": "True", "reason_to_pay": "I would not pay for it as I am looking for an online community to help people find dates. But for products related to dating, paying for it would be a no-brainer.","fg_will_invest": "False", "reason_to_invest": "There are many online dating platforms already.","score": "40"}}
92
  """
93
 
94
+ sys_msg="You are demanding customer."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
  instruction = """Determine the product or solution, the problem being solved, features, target customer that are being discussed in the \
97
  following user prompt. State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.\
 
119
  response = get_completion(total_prompt)
120
  gen_text = response["predictions"][0]["generated_text"]
121
  return json.dumps(extract_json(gen_text, 3))
122
+ #return json.dumps(response)
123
+
124
+ #iface = gr.Interface(fn=greet, inputs="text", outputs="text")
125
+ #iface.launch()
126
 
127
+ #iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Text to find entities", lines=2)], outputs=[gr.HighlightedText(label="Text with entities")], title="NER with dslim/bert-base-NER", description="Find entities using the `dslim/bert-base-NER` model under the hood!", allow_flagging="never", examples=["My name is Andrew and I live in California", "My name is Poli and work at HuggingFace"])
128
+ iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Elevator pitch", lines=3)], outputs="json")
129
  iface.launch()