Spaces:
Configuration error

yonkasoft commited on
Commit
5a85e93
·
verified ·
1 Parent(s): 53f8a7d

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -67
app.py DELETED
@@ -1,67 +0,0 @@
1
- from flask import Flask, request, jsonify
2
- import pymongo
3
- import requests
4
- import json
5
- from transformers import MT5ForConditionalGeneration, MT5Tokenizer
6
- import torch
7
- from torch.nn.functional import softmax
8
-
9
- app = Flask(__name__)
10
-
11
- #hazırladığım verilere ait database
12
- mongo_client = pymongo.MongoClient('mongodb://localhost:27017/')
13
- db = mongo_client['EgitimDatabase']
14
- collection = db['test']
15
-
16
-
17
-
18
- #kullanıcılara ait inputların kaydedileceği database
19
- mongo_client = pymongo.MongoClient('mongodb://localhost:27017/')
20
- db = mongo_client['EgitimDatabase']
21
- collection = db['input']
22
-
23
-
24
-
25
-
26
-
27
- outputs = model.generate(**inputs, output_scores=True, return_dict_in_generate=True, num_beams=5)
28
- generated_text = tokenizer.decode(outputs.sequences[0], skip_special_tokens=True)
29
-
30
- return generated_text
31
-
32
- @app.route('/predict', methods=['POST'])
33
- def predict():
34
- data = request.json
35
- title = data.get('title')
36
- keywords = data.get('keywords')
37
- subheadings = data.get('subheadings')
38
-
39
- # MongoDB'den ilgili verileri çekme
40
- query = {
41
- 'title': title,
42
- 'keywords': {'$in': keywords.split(',')},
43
- 'subheadings': {'$in': subheadings.split(',')}
44
- }
45
- documents = list(collection.find(query))
46
-
47
- if not documents:
48
- return jsonify({'error': 'No documents found matching the query'}), 404
49
-
50
- # Verilerle metin oluşturma
51
- generated_texts = []
52
- for doc in documents:
53
- generated_text = generate_text(doc['title'], doc['keywords'], doc['subheadings'])
54
- generated_texts.append(generated_text)
55
-
56
- # Sonuçları döndürme
57
- response = {
58
- 'title': title,
59
- 'keywords': keywords,
60
- 'subheadings': subheadings,
61
- 'generated_texts': generated_texts
62
- }
63
-
64
- return jsonify(response)
65
-
66
- if __name__ == "__main__":
67
- app.run(host='0.0.0.0', port=8080)