generalbots/botmodels/app.py
Rodrigo Rodriguez (Pragmatismo) 037db5c381 feat: Major workspace reorganization and documentation update
- Add comprehensive documentation in botbook/ with 12 chapters
- Add botapp/ Tauri desktop application
- Add botdevice/ IoT device support
- Add botlib/ shared library crate
- Add botmodels/ Python ML models service
- Add botplugin/ browser extension
- Add botserver/ reorganized server code
- Add bottemplates/ bot templates
- Add bottest/ integration tests
- Add botui/ web UI server
- Add CI/CD workflows in .forgejo/workflows/
- Add AGENTS.md and PROD.md documentation
- Add dependency management scripts (DEPENDENCIES.sh/ps1)
- Remove legacy src/ structure and migrations
- Clean up temporary and backup files
2026-04-19 08:14:25 -03:00

50 lines
No EOL
1.1 KiB
Python

import logging
import azure.functions as func
import os
#os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from allennlp.predictors.predictor import Predictor
import json
logging.info('Starting General Bots Models server.')
# https://ai.google.com/research/NaturalQuestions
predictor = None
from flask import Flask, render_template, request
import hmac
app = Flask(__name__)
@app.route("/reading-comprehension", methods=['POST'])
def index():
logging.info('General Bots QA.')
content = request.form.get('content')
question = request.args.get('question')
key = request.args.get('key')
if not hmac.compare_digest(key, 'starter'):
return 'Invalid key.'
global predictor
if predictor is None:
predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/transformer-qa-2020-10-03.tar.gz")
answer = predictor.predict(
passage=content,
question=question
)['best_span_str']
if answer:
return answer
else:
return "No answers for this question."
app.run(debug=True)