Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from datetime import datetime
|
|
| 6 |
from os import listdir
|
| 7 |
from web import Online_Scraper
|
| 8 |
import requests
|
|
|
|
| 9 |
from time import time as t
|
| 10 |
import os
|
| 11 |
|
|
@@ -148,6 +149,65 @@ def Genration():
|
|
| 148 |
return jsonify(result)
|
| 149 |
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
@app.route('/divyanshpizza', methods=['GET'])
|
| 152 |
def get_counters():
|
| 153 |
return jsonify(counter),jsonify({"data":str(listdir(r"static/data/"))})
|
|
|
|
| 6 |
from os import listdir
|
| 7 |
from web import Online_Scraper
|
| 8 |
import requests
|
| 9 |
+
from RT import RealTimeGemini
|
| 10 |
from time import time as t
|
| 11 |
import os
|
| 12 |
|
|
|
|
| 149 |
return jsonify(result)
|
| 150 |
|
| 151 |
|
| 152 |
+
@app.route('/realtime', methods=['POST'])
|
| 153 |
+
def Genration():
|
| 154 |
+
try:
|
| 155 |
+
import google.generativeai as genai
|
| 156 |
+
generation_config = {
|
| 157 |
+
"temperature": 0.9,
|
| 158 |
+
"top_p": 1,
|
| 159 |
+
"top_k": 1,
|
| 160 |
+
"max_output_tokens": 300,
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
safety_settings = [
|
| 164 |
+
{
|
| 165 |
+
"category": "HARM_CATEGORY_HARASSMENT",
|
| 166 |
+
"threshold": "BLOCK_NONE"
|
| 167 |
+
},
|
| 168 |
+
{
|
| 169 |
+
"category": "HARM_CATEGORY_HATE_SPEECH",
|
| 170 |
+
"threshold": "BLOCK_NONE"
|
| 171 |
+
},
|
| 172 |
+
{
|
| 173 |
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
| 174 |
+
"threshold": "BLOCK_NONE"
|
| 175 |
+
},
|
| 176 |
+
{
|
| 177 |
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
| 178 |
+
"threshold": "BLOCK_NONE"
|
| 179 |
+
},
|
| 180 |
+
]
|
| 181 |
+
|
| 182 |
+
model = genai.GenerativeModel(
|
| 183 |
+
model_name="gemini-pro",
|
| 184 |
+
generation_config=generation_config,
|
| 185 |
+
safety_settings=safety_settings)
|
| 186 |
+
|
| 187 |
+
data = request.json
|
| 188 |
+
query = data.get('prompt', "hello ?")
|
| 189 |
+
messages = data.get('messages', [])
|
| 190 |
+
key = data.get('key', '')
|
| 191 |
+
|
| 192 |
+
C=t()
|
| 193 |
+
genai.configure(api_key=key)
|
| 194 |
+
response = RealTimeGemini(query,messages,model)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
# Prepare the response
|
| 198 |
+
result = {
|
| 199 |
+
'response': response,
|
| 200 |
+
'execution_time': t()-C
|
| 201 |
+
}
|
| 202 |
+
return jsonify(result)
|
| 203 |
+
except Exception as e:
|
| 204 |
+
result = {
|
| 205 |
+
'response': f"{e}",
|
| 206 |
+
'execution_time': t()-C
|
| 207 |
+
}
|
| 208 |
+
return jsonify(result)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
@app.route('/divyanshpizza', methods=['GET'])
|
| 212 |
def get_counters():
|
| 213 |
return jsonify(counter),jsonify({"data":str(listdir(r"static/data/"))})
|