Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,11 +6,43 @@ from datetime import datetime
|
|
6 |
from os import listdir
|
7 |
from web import Online_Scraper
|
8 |
import requests
|
|
|
|
|
9 |
|
10 |
app = Flask(__name__)
|
11 |
|
12 |
|
13 |
# Tracking API usage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
|
16 |
@app.route('/mistral7b', methods=['POST'])
|
@@ -87,7 +119,26 @@ def IMGEN():
|
|
87 |
|
88 |
|
89 |
return requests.post(API_URL, headers=headers, json={"inputs": prompt,}).content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
@app.route('/divyanshpizza', methods=['GET'])
|
93 |
def get_counters():
|
|
|
6 |
from os import listdir
|
7 |
from web import Online_Scraper
|
8 |
import requests
|
9 |
+
import google.generativeai as genai
|
10 |
+
from time import time as t
|
11 |
|
12 |
app = Flask(__name__)
|
13 |
|
14 |
|
15 |
# Tracking API usage
|
16 |
+
generation_config = {
|
17 |
+
"temperature": 0.7,
|
18 |
+
"top_p": 1,
|
19 |
+
"top_k": 1,
|
20 |
+
"max_output_tokens": 350,
|
21 |
+
}
|
22 |
+
|
23 |
+
safety_settings = [
|
24 |
+
{
|
25 |
+
"category": "HARM_CATEGORY_HARASSMENT",
|
26 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"category": "HARM_CATEGORY_HATE_SPEECH",
|
30 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
31 |
+
},
|
32 |
+
{
|
33 |
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
34 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
38 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
39 |
+
},
|
40 |
+
]
|
41 |
+
|
42 |
+
model = genai.GenerativeModel(
|
43 |
+
model_name="gemini-pro",
|
44 |
+
generation_config=generation_config,
|
45 |
+
safety_settings=safety_settings)
|
46 |
|
47 |
|
48 |
@app.route('/mistral7b', methods=['POST'])
|
|
|
119 |
|
120 |
|
121 |
return requests.post(API_URL, headers=headers, json={"inputs": prompt,}).content
|
122 |
+
|
123 |
+
@app.route('/generativeai', methods=['POST'])
|
124 |
+
def Genration():
|
125 |
+
global model
|
126 |
+
data = request.json
|
127 |
+
prompt = data.get('prompt', '')
|
128 |
+
messages = data.get('messages', [])
|
129 |
+
key = data.get('key', '')
|
130 |
+
|
131 |
+
C=t()
|
132 |
+
genai.configure(api_key=key)
|
133 |
+
response = model.generate_content(messages)
|
134 |
|
135 |
+
|
136 |
+
# Prepare the response
|
137 |
+
result = {
|
138 |
+
'response': response.text,
|
139 |
+
'execution_time': t()-C
|
140 |
+
}
|
141 |
+
return jsonify(result)
|
142 |
|
143 |
@app.route('/divyanshpizza', methods=['GET'])
|
144 |
def get_counters():
|