Spaces:
Sleeping
Sleeping
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 ### | |
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"] | |
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'] | |
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 | |
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 = "[email protected]" | |
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) | |
def home(): | |
return render_template('index.html') | |
if __name__ == '__main__': | |
app.run(debug=True) | |