Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,20 @@
|
|
1 |
-
|
2 |
-
|
3 |
import gradio as gr
|
4 |
from transformers import pipeline
|
5 |
import requests
|
|
|
6 |
|
7 |
# Load the sentiment analysis model
|
8 |
classifier = pipeline('sentiment-analysis', model='krishnamishra8848/movie_sentiment_analysis')
|
9 |
|
|
|
|
|
|
|
10 |
# Language detection function
|
11 |
def detect_language(text):
|
12 |
detect_url = "https://google-translator9.p.rapidapi.com/v2/detect"
|
13 |
detect_payload = {"q": text}
|
14 |
headers = {
|
15 |
-
"x-rapidapi-key":
|
16 |
"x-rapidapi-host": "google-translator9.p.rapidapi.com",
|
17 |
"Content-Type": "application/json"
|
18 |
}
|
@@ -34,7 +36,7 @@ def translate_text(text, source_language, target_language="en"):
|
|
34 |
"format": "text"
|
35 |
}
|
36 |
headers = {
|
37 |
-
"x-rapidapi-key":
|
38 |
"x-rapidapi-host": "google-translator9.p.rapidapi.com",
|
39 |
"Content-Type": "application/json"
|
40 |
}
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
import requests
|
4 |
+
import os # Import for accessing environment variables
|
5 |
|
6 |
# Load the sentiment analysis model
|
7 |
classifier = pipeline('sentiment-analysis', model='krishnamishra8848/movie_sentiment_analysis')
|
8 |
|
9 |
+
# Get API key from secrets
|
10 |
+
RAPIDAPI_KEY = os.environ.get("RAPIDAPI_KEY") # Securely access the secret
|
11 |
+
|
12 |
# Language detection function
|
13 |
def detect_language(text):
|
14 |
detect_url = "https://google-translator9.p.rapidapi.com/v2/detect"
|
15 |
detect_payload = {"q": text}
|
16 |
headers = {
|
17 |
+
"x-rapidapi-key": RAPIDAPI_KEY, # Use the secret here
|
18 |
"x-rapidapi-host": "google-translator9.p.rapidapi.com",
|
19 |
"Content-Type": "application/json"
|
20 |
}
|
|
|
36 |
"format": "text"
|
37 |
}
|
38 |
headers = {
|
39 |
+
"x-rapidapi-key": RAPIDAPI_KEY, # Use the secret here
|
40 |
"x-rapidapi-host": "google-translator9.p.rapidapi.com",
|
41 |
"Content-Type": "application/json"
|
42 |
}
|