Spaces:
Configuration error
Configuration error
File size: 1,851 Bytes
2ccc687 8225082 2ccc687 8225082 2ccc687 8225082 2ccc687 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
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)
|