Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import pandas as pd
|
|
| 3 |
import plotly.express as px
|
| 4 |
from textblob import TextBlob
|
| 5 |
from deep_translator import GoogleTranslator, exceptions
|
|
|
|
| 6 |
import time
|
| 7 |
|
| 8 |
# Konfigurasi Halaman
|
|
@@ -15,16 +16,16 @@ if "results" not in st.session_state:
|
|
| 15 |
|
| 16 |
translator = GoogleTranslator(source='auto', target='en')
|
| 17 |
|
| 18 |
-
# Fungsi untuk menerjemahkan dengan retry jika terjadi TooManyRequests
|
| 19 |
def safe_translate(text):
|
| 20 |
try:
|
| 21 |
return translator.translate(text)
|
| 22 |
except exceptions.TooManyRequests:
|
| 23 |
-
time.sleep(
|
| 24 |
try:
|
| 25 |
return translator.translate(text)
|
| 26 |
except exceptions.TooManyRequests:
|
| 27 |
-
return
|
| 28 |
|
| 29 |
# Input Kalimat
|
| 30 |
st.subheader("📝 Masukkan Teks untuk Analisis Sentimen")
|
|
@@ -105,4 +106,4 @@ if st.session_state["results"]:
|
|
| 105 |
|
| 106 |
# Tambahkan file requirements.txt untuk deploy di Hugging Face
|
| 107 |
with open("requirements.txt", "w") as f:
|
| 108 |
-
f.write("streamlit\npandas\nplotly\ntextblob\ndeep-translator")
|
|
|
|
| 3 |
import plotly.express as px
|
| 4 |
from textblob import TextBlob
|
| 5 |
from deep_translator import GoogleTranslator, exceptions
|
| 6 |
+
import mtranslate
|
| 7 |
import time
|
| 8 |
|
| 9 |
# Konfigurasi Halaman
|
|
|
|
| 16 |
|
| 17 |
translator = GoogleTranslator(source='auto', target='en')
|
| 18 |
|
| 19 |
+
# Fungsi untuk menerjemahkan dengan retry jika terjadi TooManyRequests atau gagal
|
| 20 |
def safe_translate(text):
|
| 21 |
try:
|
| 22 |
return translator.translate(text)
|
| 23 |
except exceptions.TooManyRequests:
|
| 24 |
+
time.sleep(5) # Tambah jeda waktu untuk menghindari blokir
|
| 25 |
try:
|
| 26 |
return translator.translate(text)
|
| 27 |
except exceptions.TooManyRequests:
|
| 28 |
+
return mtranslate.translate(text, "en") # Alternatif penerjemah
|
| 29 |
|
| 30 |
# Input Kalimat
|
| 31 |
st.subheader("📝 Masukkan Teks untuk Analisis Sentimen")
|
|
|
|
| 106 |
|
| 107 |
# Tambahkan file requirements.txt untuk deploy di Hugging Face
|
| 108 |
with open("requirements.txt", "w") as f:
|
| 109 |
+
f.write("streamlit\npandas\nplotly\ntextblob\ndeep-translator\nmtranslate")
|