Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -5,8 +5,12 @@ import requests
|
|
| 5 |
from flask import Flask, request, jsonify
|
| 6 |
from werkzeug.utils import secure_filename
|
| 7 |
import google.generativeai as genai
|
|
|
|
| 8 |
from flask_cors import CORS
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
try:
|
| 11 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 12 |
except TypeError:
|
|
@@ -117,7 +121,8 @@ def process_query():
|
|
| 117 |
classification = SESSIONS[session_id].get('classification')
|
| 118 |
category = classification['category']
|
| 119 |
endpoint_url = API_ENDPOINTS.get(category)
|
| 120 |
-
|
|
|
|
| 121 |
del SESSIONS[session_id]
|
| 122 |
print(f"Session {session_id} closed.")
|
| 123 |
return jsonify({
|
|
@@ -184,3 +189,5 @@ def process_with_image():
|
|
| 184 |
print(f"Session {session_id} closed after failed API call.")
|
| 185 |
return jsonify({"status": "error", "message": f"Backend service call failed: {e}"}), 503
|
| 186 |
|
|
|
|
|
|
|
|
|
| 5 |
from flask import Flask, request, jsonify
|
| 6 |
from werkzeug.utils import secure_filename
|
| 7 |
import google.generativeai as genai
|
| 8 |
+
from dotenv import load_dotenv
|
| 9 |
from flask_cors import CORS
|
| 10 |
|
| 11 |
+
|
| 12 |
+
# Step 1: API Key aur Environment Setup
|
| 13 |
+
load_dotenv()
|
| 14 |
try:
|
| 15 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 16 |
except TypeError:
|
|
|
|
| 121 |
classification = SESSIONS[session_id].get('classification')
|
| 122 |
category = classification['category']
|
| 123 |
endpoint_url = API_ENDPOINTS.get(category)
|
| 124 |
+
payload={"query": query}
|
| 125 |
+
response = requests.post(endpoint_url,data=payload, json={"main_query": query})
|
| 126 |
del SESSIONS[session_id]
|
| 127 |
print(f"Session {session_id} closed.")
|
| 128 |
return jsonify({
|
|
|
|
| 189 |
print(f"Session {session_id} closed after failed API call.")
|
| 190 |
return jsonify({"status": "error", "message": f"Backend service call failed: {e}"}), 503
|
| 191 |
|
| 192 |
+
if __name__ == '__main__':
|
| 193 |
+
app.run(debug=True, port=5000)
|