DIVY118 commited on
Commit
e67f3b2
·
verified ·
1 Parent(s): bc93908

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -33
app.py CHANGED
@@ -11,7 +11,36 @@ from time import time as t
11
 
12
  app = Flask(__name__)
13
 
14
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
 
17
 
@@ -92,44 +121,14 @@ def IMGEN():
92
 
93
  @app.route('/generativeai', methods=['POST'])
94
  def Genration():
95
- global model
96
  data = request.json
97
  prompt = data.get('prompt', '')
98
  messages = data.get('messages', [])
99
  key = data.get('key', '')
100
 
101
  C=t()
102
- # Tracking API usage
103
- generation_config = {
104
- "temperature": 0.7,
105
- "top_p": 1,
106
- "top_k": 1,
107
- "max_output_tokens": 350,
108
- }
109
-
110
- safety_settings = [
111
- {
112
- "category": "HARM_CATEGORY_HARASSMENT",
113
- "threshold": "BLOCK_MEDIUM_AND_ABOVE"
114
- },
115
- {
116
- "category": "HARM_CATEGORY_HATE_SPEECH",
117
- "threshold": "BLOCK_MEDIUM_AND_ABOVE"
118
- },
119
- {
120
- "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
121
- "threshold": "BLOCK_MEDIUM_AND_ABOVE"
122
- },
123
- {
124
- "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
125
- "threshold": "BLOCK_MEDIUM_AND_ABOVE"
126
- },
127
- ]
128
-
129
- model = genai.GenerativeModel(
130
- model_name="gemini-pro",
131
- generation_config=generation_config,
132
- safety_settings=safety_settings)
133
  genai.configure(api_key=key)
134
  response = model.generate_content(messages)
135
 
 
11
 
12
  app = Flask(__name__)
13
 
14
+ generation_config = {
15
+ "temperature": 0.7,
16
+ "top_p": 1,
17
+ "top_k": 1,
18
+ "max_output_tokens": 512,
19
+ }
20
+
21
+ safety_settings = [
22
+ {
23
+ "category": "HARM_CATEGORY_HARASSMENT",
24
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
25
+ },
26
+ {
27
+ "category": "HARM_CATEGORY_HATE_SPEECH",
28
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
29
+ },
30
+ {
31
+ "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
32
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
33
+ },
34
+ {
35
+ "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
36
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
37
+ },
38
+ ]
39
+
40
+ model = genai.GenerativeModel(
41
+ model_name="gemini-pro",
42
+ generation_config=generation_config,
43
+ safety_settings=safety_settings)
44
 
45
 
46
 
 
121
 
122
  @app.route('/generativeai', methods=['POST'])
123
  def Genration():
124
+ global model,safety_settings,generation_config
125
  data = request.json
126
  prompt = data.get('prompt', '')
127
  messages = data.get('messages', [])
128
  key = data.get('key', '')
129
 
130
  C=t()
131
+ genai.configure(api_key=key)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  genai.configure(api_key=key)
133
  response = model.generate_content(messages)
134