skyvera commited on
Commit
44c2d91
verified
1 Parent(s): 70b8e61

Upload 3 files

Browse files
Files changed (2) hide show
  1. app.py +59 -2
  2. requirements.txt +2 -1
app.py CHANGED
@@ -42,7 +42,48 @@ def make_api_call(authorization_key, prompt, phone_number):
42
  logging.info(f"API call response: {response.json()}")
43
  return response.json()
44
 
45
- interface = gr.Interface(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  fn=make_api_call,
47
  inputs=[
48
  gr.Textbox(label="API Key", placeholder="Enter your API Key, e.g., sk-n 路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路"),
@@ -53,4 +94,20 @@ interface = gr.Interface(
53
  description="Create your bland.ai account if you don't have one yet through [this link](https://app.bland.ai/signup). After creating your account, you can find your API key under the 'API Key' tab in your dashboard settings [here](https://app.bland.ai/dashboard?page=settings)."
54
  )
55
 
56
- interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  logging.info(f"API call response: {response.json()}")
43
  return response.json()
44
 
45
+ def analyze_call(authorization_key, call_id, goal, questions, types):
46
+ logging.info(f"Analyzing call with ID: {call_id}")
47
+
48
+ formatted_questions = format_questions(questions, types)
49
+
50
+ url = f"https://api.bland.ai/v1/calls/{call_id}/analyze"
51
+ payload = {
52
+ "goal": goal,
53
+ "questions": formatted_questions
54
+ }
55
+ headers = {
56
+ "Authorization": authorization_key,
57
+ "Content-Type": "application/json"
58
+ }
59
+
60
+ response = requests.post(url, json=payload, headers=headers)
61
+ if response.status_code == 200:
62
+ try:
63
+ response_data = response.json()
64
+ logging.info(f"Call analysis response: {response_data}")
65
+ return response_data
66
+ except ValueError:
67
+ logging.error("Invalid JSON response received.")
68
+ return {"error": "Invalid JSON response received"}
69
+ else:
70
+ logging.error(f"Failed to analyze call: {response.status_code}")
71
+ return {"error": "API call failed", "status_code": response.status_code}
72
+
73
+ def format_questions(questions, types):
74
+ # Split the input strings into individual questions and types
75
+ question_list = questions.split(';')
76
+ type_list = types.split(';')
77
+
78
+ # Combine questions and types into a formatted list
79
+ formatted_questions = []
80
+ for question, type in zip(question_list, type_list):
81
+ formatted_questions.append([question.strip(), type.strip()])
82
+
83
+ return formatted_questions
84
+
85
+ # Interface for making API calls
86
+ make_call_interface = gr.Interface(
87
  fn=make_api_call,
88
  inputs=[
89
  gr.Textbox(label="API Key", placeholder="Enter your API Key, e.g., sk-n 路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路"),
 
94
  description="Create your bland.ai account if you don't have one yet through [this link](https://app.bland.ai/signup). After creating your account, you can find your API key under the 'API Key' tab in your dashboard settings [here](https://app.bland.ai/dashboard?page=settings)."
95
  )
96
 
97
+ # Interface for analyzing calls
98
+ analyze_call_interface = gr.Interface(
99
+ fn=analyze_call,
100
+ inputs=[
101
+ gr.Textbox(label="API Key", placeholder="Enter your API Key, e.g., sk-n 路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路路"),
102
+ gr.Textbox(label="Call ID", placeholder="Enter the ID of the call to analyze"),
103
+ gr.Textbox(label="Goal", placeholder="Enter the goal of the call analysis", info="This is the overall purpose of the call. Provides context for the analysis to guide how the questions/transcripts are interpreted."),
104
+ gr.Textbox(label="Questions", lines=2, placeholder="Enter questions separated by semicolons, e.g., 'Who answered the call?;Was the customer satisfied?;What was the customer's main concern?'"),
105
+ gr.Textbox(label="Answer Types", lines=2, placeholder="Enter answer types for each question separated by semicolons, e.g., 'human or voicemail;boolean;string'", info="Specify the expected answer type for each question, corresponding to the order of questions. Types include 'string', 'boolean', etc. Unanswerable questions will default to null.")
106
+ ],
107
+ outputs="json",
108
+ description="Analyze the results of your phone calls. Enter questions in one textbox and their corresponding expected answer types in another, separated by semicolons for multiple entries."
109
+ )
110
+
111
+ # Combine interfaces into tabs
112
+ demo = gr.TabbedInterface([make_call_interface, analyze_call_interface], ["Make Call", "Analyze Call"])
113
+ demo.launch()
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  gradio
2
- requests
 
 
1
  gradio
2
+ requests
3
+ logging