burask commited on
Commit
7a7248b
·
verified ·
1 Parent(s): 4c80c5f

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +11 -0
  2. app.py +82 -0
  3. requirements.txt +0 -0
  4. templates/index.html +119 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ RUN apt-get update && apt-get install -y ffmpeg
4
+
5
+ COPY requirements.txt /app/requirements.txt
6
+ RUN pip install --no-cache-dir -r /app/requirements.txt
7
+
8
+ COPY . /app
9
+ WORKDIR /app
10
+
11
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request
2
+ import os
3
+ import subprocess
4
+ from speech_recognition import Recognizer, AudioFile
5
+ from werkzeug.utils import secure_filename
6
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
7
+ from deepmultilingualpunctuation import PunctuationModel
8
+
9
+ app = Flask(__name__)
10
+ yuklenen_dosyalar = "uploads"
11
+ app.config["yuklenen_dosyalar"] = yuklenen_dosyalar
12
+ dosya_turleri = {"mp3", "m4a"}
13
+
14
+ # Modelleri yükle
15
+ tokenizer = AutoTokenizer.from_pretrained("csebuetnlp/mT5_multilingual_XLSum")
16
+ model = AutoModelForSeq2SeqLM.from_pretrained("csebuetnlp/mT5_multilingual_XLSum")
17
+ punct_model = PunctuationModel(model="oliverguhr/fullstop-punctuation-multilingual-sonar-base")
18
+
19
+ def metin_duzenleme(text):
20
+ text = text.strip()
21
+ try:
22
+ return punct_model.restore_punctuation(text)
23
+ except Exception as e:
24
+ print("Noktalama hatası:", e)
25
+ return text
26
+
27
+ def metin_ozetleme(text):
28
+ girilen_metin = "tr: " + text
29
+ girilenler = tokenizer([girilen_metin], return_tensors="pt", max_length=10000, truncation=True)
30
+ summary_ids = model.generate(
31
+ girilenler["input_ids"],
32
+ max_length=1000,
33
+ min_length=1,
34
+ length_penalty=1.0,
35
+ num_beams=4,
36
+ early_stopping=True
37
+ )
38
+ return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
39
+
40
+ def uygun_turler(filename):
41
+ return "." in filename and filename.rsplit(".", 1)[1].lower() in dosya_turleri
42
+
43
+ def convert_mp3_to_wav(mp3_path):
44
+ wav_path = mp3_path.rsplit('.', 1)[0] + '.wav'
45
+ subprocess.run(['ffmpeg', '-i', mp3_path, wav_path, '-y'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
46
+ return wav_path
47
+
48
+ def ses_donusturucu(wav_path):
49
+ recognizer = Recognizer()
50
+ with AudioFile(wav_path) as source:
51
+ ses = recognizer.record(source)
52
+ try:
53
+ return recognizer.recognize_google(ses, language="tr-TR")
54
+ except Exception as e:
55
+ return f"Ses tanıma hatası: {e}"
56
+
57
+ @app.route("/", methods=["GET", "POST"])
58
+ def index():
59
+ if request.method == "POST":
60
+ if "file" not in request.files:
61
+ return "Dosya bulunamadı."
62
+ file = request.files["file"]
63
+ if file.filename == "":
64
+ return "Dosya seçilmedi."
65
+ if file and uygun_turler(file.filename):
66
+ filename = secure_filename(file.filename)
67
+ file_path = os.path.join(app.config["yuklenen_dosyalar"], filename)
68
+ file.save(file_path)
69
+
70
+ wav_path = convert_mp3_to_wav(file_path)
71
+ raw_text = ses_donusturucu(wav_path)
72
+ metin = metin_duzenleme(raw_text)
73
+ ozet = metin_ozetleme(metin)
74
+
75
+ return render_template("index.html", metin=metin, ozet=ozet)
76
+ return render_template("index.html")
77
+
78
+ if __name__ == "__main__":
79
+ if not os.path.exists(yuklenen_dosyalar):
80
+ os.makedirs(yuklenen_dosyalar)
81
+ port = int(os.environ.get("PORT", 7860)) # Hugging Face için 7860 port
82
+ app.run(host="0.0.0.0", port=port, debug=False)
requirements.txt ADDED
Binary file (204 Bytes). View file
 
templates/index.html ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="tr">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>🎙️Transkript</title>
6
+ <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
7
+ <style>
8
+ html, body {
9
+ margin: 0;
10
+ padding: 0;
11
+ height: 100%;
12
+ font-family: "cursive";
13
+ overflow: hidden;
14
+ display: flex;
15
+ justify-content: center;
16
+ align-items: center;
17
+ }
18
+
19
+ #particles-js {
20
+ position: fixed;
21
+ width: 100%;
22
+ height: 100%;
23
+ background-color: #0d1b2a;
24
+ z-index: -1;
25
+ }
26
+
27
+ .container {
28
+ max-width: 1000px;
29
+ width: 95%;
30
+ background: rgba(176, 26, 26, 0.459);
31
+ padding: 50px;
32
+ border-radius: 20px;
33
+ box-shadow: 0 0 30px rgba(255, 255, 255, 0.3);
34
+ z-index: 1;
35
+ color: #fff;
36
+ }
37
+
38
+ .output-box {
39
+ margin-top: 15px;
40
+ background: #e9ecef;
41
+ padding: 10px;
42
+ border-radius: 10px;
43
+ white-space: pre-wrap;
44
+ max-height: 300px;
45
+ overflow-y: auto;
46
+ color: #000;
47
+ }
48
+
49
+ .output-box h2,
50
+ .output-box h3,
51
+ .output-box p {
52
+ margin-top: 5px;
53
+ margin-bottom: 5px;
54
+ }
55
+
56
+
57
+ </style>
58
+ </head>
59
+ <body>
60
+ <div id="particles-js"></div>
61
+
62
+ <div class="container">
63
+ <h2 class="text-center mb-4">🎙️ Ses Dosyasını Metne Dönüştür</h2>
64
+ <form method="POST" enctype="multipart/form-data">
65
+ <div class="mb-3">
66
+ <label for="file" class="form-label">Ses Dosyası Seç (.mp3)</label>
67
+ <input class="form-control" type="file" name="file" id="file" required>
68
+ </div>
69
+ <div class="d-grid">
70
+ <button type="submit" class="btn btn-primary btn-lg">Yükle ve Dönüştür</button>
71
+ </div>
72
+ </form>
73
+
74
+ {% if metin %}
75
+ <div class="output-box mt-1">
76
+ <h5>🎧 Dönüştürülen Metin:</h5>
77
+ <p>{{ metin }}</p>
78
+ </div>
79
+ {% if ozet %}
80
+ <div class="output-box mt-4">
81
+ <h5>📝 Metnin Özeti:</h5>
82
+ <p>{{ ozet }}</p>
83
+ </div>
84
+ {% endif %}
85
+ {% endif %}
86
+
87
+ </div>
88
+
89
+ <p style="position: fixed; bottom: 20px; left: 20px; color:#ffffff;">Designer by: Burak Tuğrul Aşık & Tarık Kahraman</p>
90
+
91
+ <script src="https://cdn.jsdelivr.net/npm/particles.js"></script>
92
+ <script>
93
+ particlesJS('particles-js', {
94
+ "particles": {
95
+ "number": { "value": 90, "density": { "enable": true, "value_area": 800 } },
96
+ "color": { "value": "#ffffff" },
97
+ "shape": { "type": "star", "stroke": { "width": 0, "color": "#ffffff" }, "polygon": { "nb_sides": 5 } },
98
+ "opacity": { "value": 0.5, "random": false },
99
+ "size": { "value": 3, "random": false },
100
+ "line_linked": { "enable": true, "distance": 150, "color": "#ffffff", "opacity": 0.4, "width": 1 },
101
+ "move": { "enable": true, "speed": 1, "direction": "none", "random": false, "straight": false, "out_mode": "out", "bounce": false }
102
+ },
103
+ "interactivity": {
104
+ "detect_on": "canvas",
105
+ "events": {
106
+ "onhover": { "enable": true, "mode": "repulse" },
107
+ "onclick": { "enable": true, "mode": "push" },
108
+ "resize": true
109
+ },
110
+ "modes": {
111
+ "repulse": { "distance": 100, "duration": 0.4 },
112
+ "push": { "particles_nb": 4 }
113
+ }
114
+ },
115
+ "retina_detect": true
116
+ });
117
+ </script>
118
+ </body>
119
+ </html>