Aum-Kansara commited on
Commit
9fc507e
·
1 Parent(s): a6a194c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +93 -0
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ from dotenv import load_dotenv
3
+ import os
4
+ from flask import Flask,jsonify,request
5
+
6
+ load_dotenv()
7
+ openai.api_key=os.getenv("OPENAI_API_KEY")
8
+ def sentiment_analysis(transcription):
9
+ response = openai.ChatCompletion.create(
10
+ model="gpt-3.5-turbo",
11
+ temperature=0,
12
+ messages=[
13
+ {
14
+ "role": "system",
15
+ "content": "As an AI with expertise in language and emotion analysis, your task is to analyze the sentiment of the following text. Please consider the overall tone of the discussion, the emotion conveyed by the language used, and the context in which words and phrases are used. Indicate whether the sentiment is generally positive, negative, or neutral, and provide brief explanations for your analysis where possible. just say in one word"
16
+ },
17
+ {
18
+ "role": "user",
19
+ "content": transcription
20
+ }
21
+ ]
22
+ )
23
+ return response['choices'][0]['message']['content']
24
+
25
+ def positive_summary_extraction(transcription):
26
+ response = openai.ChatCompletion.create(
27
+ model="gpt-3.5-turbo",
28
+ temperature=0,
29
+ messages=[
30
+ {
31
+ "role": "system",
32
+ "content": "The following is information from a customer on his/her experience with our Anytime Fitness gym branch. Please create a 2-3 sentence review based on this info that is cheerful and reflects well on the business include emojis"
33
+ },
34
+ {
35
+ "role": "user",
36
+ "content": transcription
37
+ }
38
+ ]
39
+ )
40
+ return response['choices'][0]['message']['content']
41
+
42
+
43
+ def nagetive_summary_extraction(transcription):
44
+ response = openai.ChatCompletion.create(
45
+ model="gpt-3.5-turbo",
46
+ temperature=0,
47
+ messages=[
48
+ {
49
+ "role": "system",
50
+ "content": "The following is information for feedback from a customer on his/her negative experience with our Anytime Fitness gym branch. Please create a 2-3 sentence summary based on this info that is objective and to the point so the gym understands what to do next"
51
+ },
52
+ {
53
+ "role": "user",
54
+ "content": transcription
55
+ }
56
+ ]
57
+ )
58
+ return response['choices'][0]['message']['content']
59
+
60
+ app=Flask(__name__)
61
+
62
+
63
+ @app.route('/')
64
+ def index():
65
+ return "Hello World"
66
+
67
+ @app.route('/sentiment')
68
+ def getSentiment():
69
+ query=request.args.get('query','')
70
+ if query.strip()=='':
71
+ return "Provide Valid Question"
72
+ return jsonify({"question" : query,
73
+ "answer" : sentiment_analysis(query)
74
+ })
75
+
76
+ @app.route('/summarize')
77
+ def getSummary():
78
+ query_type=request.args.get('type','positive')
79
+ query=request.args.get('query','')
80
+ if query.strip()=='':
81
+ return "Provide Valid Question"
82
+ elif query_type.lower()=='positive':
83
+ return jsonify({"question" : query,
84
+ "answer" : positive_summary_extraction(query)
85
+ })
86
+ elif query_type.lower()=='negative':
87
+ return jsonify({"question" : query,
88
+ "answer" : nagetive_summary_extraction(query)
89
+ })
90
+ return "Provide Valid Question"
91
+
92
+ if __name__=="__main__":
93
+ app.run(debug=True)