Spaces:
Sleeping
Sleeping
File size: 3,810 Bytes
a9c44e2 8e34cf7 a9c44e2 8e34cf7 a9c44e2 8e34cf7 a9c44e2 |
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
from flask import Flask, render_template, request, jsonify, send_file
import speech_recognition as sr
import requests
import smtplib
from email.message import EmailMessage
from transformers import pipeline
from reportlab.pdfgen import canvas
import os
app = Flask(__name__)
# Google Speech-to-Text API Anahtarı (JSON dosyanızın yolu)
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "your-google-cloud-key.json"
# Gemini API Anahtarı
GEMINI_API_KEY = "your-gemini-api-key"
# Hugging Face Özetleme Modeli
summary_pipeline = pipeline("summarization", model="facebook/bart-large-cnn")
### 📌 1️⃣ Speech-to-Text API ###
@app.route('/speech-to-text', methods=['POST'])
def speech_to_text():
if 'audio' not in request.files:
return jsonify({"error": "No audio file provided"}), 400
audio_file = request.files['audio']
recognizer = sr.Recognizer()
with sr.AudioFile(audio_file) as source:
audio_data = recognizer.record(source)
try:
text = recognizer.recognize_google(audio_data, language="tr-TR")
return jsonify({"text": text})
except sr.UnknownValueError:
return jsonify({"error": "Could not understand audio"})
except sr.RequestError:
return jsonify({"error": "Could not request results"})
### 📌 2️⃣ Metni Özetleme (Gemini API) ###
def summarize_text(text):
url = "https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateText"
headers = {"Authorization": f"Bearer {GEMINI_API_KEY}"}
payload = {
"prompt": f"Summarize this meeting transcript:\n{text}",
"max_tokens": 500
}
response = requests.post(url, json=payload, headers=headers)
return response.json()["choices"][0]["text"]
@app.route('/summarize', methods=['POST'])
def summarize():
data = request.get_json()
text = data.get("text")
if not text:
return jsonify({"error": "No text provided"}), 400
summary = summarize_text(text)
return jsonify({"summary": summary})
### 📌 3️⃣ Kararları Çıkarma (Hugging Face NLP) ###
def extract_decisions(text):
summary = summary_pipeline(text, max_length=100, min_length=30, do_sample=False)
return summary[0]['summary_text']
@app.route('/extract-decisions', methods=['POST'])
def extract():
data = request.get_json()
text = data.get("text")
if not text:
return jsonify({"error": "No text provided"}), 400
decisions = extract_decisions(text)
return jsonify({"decisions": decisions})
### 📌 4️⃣ PDF Raporu Oluşturma ###
def create_pdf(text, filename="meeting_report.pdf"):
c = canvas.Canvas(filename)
c.drawString(100, 750, "Meeting Report")
c.drawString(100, 730, text)
c.save()
return filename
@app.route('/generate-pdf', methods=['POST'])
def generate_pdf():
data = request.get_json()
text = data.get("text")
if not text:
return jsonify({"error": "No text provided"}), 400
pdf_file = create_pdf(text)
return send_file(pdf_file, as_attachment=True)
### 📌 5️⃣ E-Posta Gönderme ###
def send_email(pdf_file, recipient_email):
email = "your-email@gmail.com"
password = "your-email-password"
msg = EmailMessage()
msg['Subject'] = 'Meeting Report'
msg['From'] = email
msg['To'] = recipient_email
msg.set_content('The meeting report is attached.')
with open(pdf_file, 'rb') as f:
file_data = f.read()
msg.add_attachment(file_data, maintype='application', subtype='pdf', filename=pdf_file)
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as server:
server.login(email, password)
server.send_message(msg)
@app.route('/')
def home():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
|