TarSh8654 commited on
Commit
0d04e6a
·
verified ·
1 Parent(s): 4777810

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ from flask import Flask, request, jsonify
3
+ import requests
4
+ import json
5
+ import asyncio # Import asyncio for running async functions
6
+
7
+ app = Flask(__name__)
8
+
9
+ # (Include your generate_solution_python function here,
10
+ # making sure to adjust the API endpoint for google_search if necessary)
11
+
12
+ # Assuming generate_solution_python is defined as in your Canvas
13
+ # You'll need to make sure the requests.post for google_search points to a valid endpoint
14
+ # In a real Hugging Face Space, you might not have a direct /api/google_search.
15
+ # You'd need to consider how to integrate a search API (e.g., Google Custom Search API, SerpAPI)
16
+ # and handle its API key securely.
17
+
18
+ @app.route('/generate', methods=['POST'])
19
+ async def generate():
20
+ data = request.json
21
+ user_query = data.get('query')
22
+ if not user_query:
23
+ return jsonify({"error": "Query is required"}), 400
24
+
25
+ # Run the async function
26
+ response_text = await generate_solution_python(user_query)
27
+ return jsonify({"solution": response_text})
28
+
29
+ if __name__ == '__main__':
30
+ app.run(host='0.0.0.0', port=7860) # Hugging Face Spaces typically use port 7860