Download app.py from bhlewis/Server: direct link, hf CLI and curl.
- Browser
- Download file 995 Bytes
-
https://huggingface.co/spaces/bhlewis/Server/resolve/main/app.py
- Command line
-
hf download hf://spaces/bhlewis/Server/app.py
-
curl -L -o app.py https://huggingface.co/spaces/bhlewis/Server/resolve/main/app.py
995 Bytes
| from flask import Flask, request, jsonify | |
| from gradio_client import Client | |
| import os | |
| app = Flask(__name__) | |
| # Initialize the Gradio client | |
| gradio_client = Client("bhlewis/BERT-for-Patents_Semantic-Patent-Finder-v2") | |
| def home(): | |
| return "Server is running. Use /api/predict for predictions." | |
| def predict(): | |
| try: | |
| data = request.json | |
| query = data.get('query', '') | |
| top_k = data.get('top_k', 5) | |
| print(f"Received query: {query}") | |
| print(f"Top K: {top_k}") | |
| result = gradio_client.predict( | |
| query=query, | |
| top_k=top_k, | |
| api_name="/predict" | |
| ) | |
| print(f"Result: {result}") | |
| return jsonify({"result": result}) | |
| except Exception as e: | |
| print(f"Error: {str(e)}") | |
| return jsonify({"error": str(e)}), 500 | |
| if __name__ == "__main__": | |
| port = int(os.environ.get("PORT", 7860)) | |
| app.run(host='0.0.0.0', port=port) | |