Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from googletrans import Translator
|
| 4 |
+
from gtts import gTTS
|
| 5 |
+
import base64
|
| 6 |
+
|
| 7 |
+
# Sayfa Ayarları (Mobil uyumlu)
|
| 8 |
+
st.set_page_config(page_title="AI Dil Asistanı", layout="centered")
|
| 9 |
+
|
| 10 |
+
@st.cache_resource
|
| 11 |
+
def load_models():
|
| 12 |
+
# Dil tespiti için özel eğitilmiş model
|
| 13 |
+
lang_detector = pipeline("text-classification", model="papluca/xlm-roberta-base-language-detection")
|
| 14 |
+
return lang_detector
|
| 15 |
+
|
| 16 |
+
detector = load_models()
|
| 17 |
+
translator = Translator()
|
| 18 |
+
|
| 19 |
+
st.title("🤖 Yapay Zeka Dil Asistanı")
|
| 20 |
+
st.markdown("Herhangi bir dilde metin girin, sistemi otomatik tanısın ve çevirsin.")
|
| 21 |
+
|
| 22 |
+
# Metin Girişi
|
| 23 |
+
user_input = st.text_area("Metni buraya yazın:", height=150)
|
| 24 |
+
|
| 25 |
+
if user_input:
|
| 26 |
+
# 1. Aşama: Dil Tespiti (Hazır Model ile)
|
| 27 |
+
detection = detector(user_input)[0]
|
| 28 |
+
detected_lang_code = detection['label']
|
| 29 |
+
|
| 30 |
+
st.info(f"**Tespit Edilen Dil Kodu:** {detected_lang_code.upper()} (Güven Skoru: %{round(detection['score']*100, 2)})")
|
| 31 |
+
|
| 32 |
+
# 2. Aşama: Çeviri Seçimi
|
| 33 |
+
target_option = st.selectbox(
|
| 34 |
+
"Hangi dile çevrilsin?",
|
| 35 |
+
["Türkçe", "İngilizce", "Almanca"]
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
lang_map = {"Türkçe": "tr", "İngilizce": "en", "Almanca": "de"}
|
| 39 |
+
target_lang = lang_map[target_option]
|
| 40 |
+
|
| 41 |
+
if st.button("Çevir ve Seslendir"):
|
| 42 |
+
with st.spinner('İşleniyor...'):
|
| 43 |
+
try:
|
| 44 |
+
# Çeviri işlemi
|
| 45 |
+
translation = translator.translate(user_input, dest=target_lang)
|
| 46 |
+
st.success(f"**{target_option} Çeviri:** {translation.text}")
|
| 47 |
+
|
| 48 |
+
# 3. Aşama: Seslendirme
|
| 49 |
+
tts = gTTS(text=translation.text, lang=target_lang)
|
| 50 |
+
tts.save("voicemail.mp3")
|
| 51 |
+
|
| 52 |
+
# Ses dosyasını oynat
|
| 53 |
+
with open("voicemail.mp3", "rb") as f:
|
| 54 |
+
st.audio(f.read(), format="audio/mp3")
|
| 55 |
+
|
| 56 |
+
except Exception as e:
|
| 57 |
+
st.error("Bir hata oluştu, lütfen tekrar deneyin.")
|