Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -91,55 +91,63 @@ def IMGEN():
|
|
| 91 |
|
| 92 |
@app.route('/generativeai', methods=['POST'])
|
| 93 |
def Genration():
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 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 |
-
genai.configure(api_key=key)
|
| 134 |
-
response = model.generate_content(messages)
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
# Prepare the response
|
| 138 |
-
result = {
|
| 139 |
-
'response': response.text,
|
| 140 |
-
'execution_time': t()-C
|
| 141 |
-
}
|
| 142 |
-
return jsonify(result)
|
| 143 |
|
| 144 |
@app.route('/divyanshpizza', methods=['GET'])
|
| 145 |
def get_counters():
|
|
|
|
| 91 |
|
| 92 |
@app.route('/generativeai', methods=['POST'])
|
| 93 |
def Genration():
|
| 94 |
+
try:
|
| 95 |
+
import google.generativeai as genai
|
| 96 |
+
generation_config = {
|
| 97 |
+
"temperature": 0.7,
|
| 98 |
+
"top_p": 1,
|
| 99 |
+
"top_k": 1,
|
| 100 |
+
"max_output_tokens": 300,
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
safety_settings = [
|
| 104 |
+
{
|
| 105 |
+
"category": "HARM_CATEGORY_HARASSMENT",
|
| 106 |
+
"threshold": "BLOCK_ONLY_HIGH"
|
| 107 |
+
},
|
| 108 |
+
{
|
| 109 |
+
"category": "HARM_CATEGORY_HATE_SPEECH",
|
| 110 |
+
"threshold": "BLOCK_ONLY_HIGH"
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
| 114 |
+
"threshold": "BLOCK_ONLY_HIGH"
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
| 118 |
+
"threshold": "BLOCK_ONLY_HIGH"
|
| 119 |
+
},
|
| 120 |
+
]
|
| 121 |
+
|
| 122 |
+
model = genai.GenerativeModel(
|
| 123 |
+
model_name="gemini-pro",
|
| 124 |
+
generation_config=generation_config,
|
| 125 |
+
safety_settings=safety_settings)
|
| 126 |
|
| 127 |
+
data = request.json
|
| 128 |
+
prompt = data.get('prompt', '')
|
| 129 |
+
messages = data.get('messages', [])
|
| 130 |
+
key = data.get('key', '')
|
| 131 |
+
|
| 132 |
+
C=t()
|
| 133 |
+
genai.configure(api_key=key)
|
| 134 |
+
genai.configure(api_key=key)
|
| 135 |
+
response = model.generate_content(messages)
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
# Prepare the response
|
| 139 |
+
result = {
|
| 140 |
+
'response': response.text,
|
| 141 |
+
'execution_time': t()-C
|
| 142 |
+
}
|
| 143 |
+
return jsonify(result)
|
| 144 |
+
except:
|
| 145 |
+
result = {
|
| 146 |
+
'response': "I'm here to provide information and assistance in a respectful manner. Inappropriate or offensive language is not acceptable. If you have a different question or topic you'd like help with, please feel free to ask, and I'll do my best to assist you.",
|
| 147 |
+
'execution_time': t()-C
|
| 148 |
+
}
|
| 149 |
+
return jsonify(result)
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
@app.route('/divyanshpizza', methods=['GET'])
|
| 153 |
def get_counters():
|