from flask import Flask, request, jsonify import pymongo import requests import json from transformers import MT5ForConditionalGeneration, MT5Tokenizer import torch from torch.nn.functional import softmax app = Flask(__name__) #hazırladığım verilere ait database mongo_client = pymongo.MongoClient('mongodb://localhost:27017/') db = mongo_client['EgitimDatabase'] collection = db['test'] #kullanıcılara ait inputların kaydedileceği database mongo_client = pymongo.MongoClient('mongodb://localhost:27017/') db = mongo_client['EgitimDatabase'] collection = db['input'] outputs = model.generate(**inputs, output_scores=True, return_dict_in_generate=True, num_beams=5) generated_text = tokenizer.decode(outputs.sequences[0], skip_special_tokens=True) return generated_text @app.route('/predict', methods=['POST']) def predict(): data = request.json title = data.get('title') keywords = data.get('keywords') subheadings = data.get('subheadings') # MongoDB'den ilgili verileri çekme query = { 'title': title, 'keywords': {'$in': keywords.split(',')}, 'subheadings': {'$in': subheadings.split(',')} } documents = list(collection.find(query)) if not documents: return jsonify({'error': 'No documents found matching the query'}), 404 # Verilerle metin oluşturma generated_texts = [] for doc in documents: generated_text = generate_text(doc['title'], doc['keywords'], doc['subheadings']) generated_texts.append(generated_text) # Sonuçları döndürme response = { 'title': title, 'keywords': keywords, 'subheadings': subheadings, 'generated_texts': generated_texts } return jsonify(response) if __name__ == "__main__": app.run(host='0.0.0.0', port=8080)