krishnamishra8848 commited on
Commit
f5b1799
·
verified ·
1 Parent(s): 69443f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
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": "ef532cb7b6msh96f36c918327aacp171ce5jsn42c4de22fe5d",
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": "ef532cb7b6msh96f36c918327aacp171ce5jsn42c4de22fe5d",
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
  }