Y4SH commited on
Commit
70b60fa
·
verified ·
1 Parent(s): 3618dce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import streamlit as st
2
  import requests
3
  import json
@@ -6,10 +7,13 @@ import matplotlib.pyplot as plt
6
  import numpy as np
7
  from io import BytesIO
8
 
9
- # Hugging Face API URLs and token
 
 
 
 
10
  TRANSLATE_API_URL = "https://api-inference.huggingface.co/models/facebook/mbart-large-50-many-to-one-mmt"
11
  IMAGE_API_URL = "https://api-inference.huggingface.co/models/CompVis/stable-diffusion-v1-4"
12
- HUGGINGFACE_TOKEN = "YOUR_HUGGINGFACE_TOKEN" # Replace with your actual token
13
  headers = {"Authorization": f"Bearer {HUGGINGFACE_TOKEN}"}
14
 
15
  # Function to translate Tamil to English
@@ -41,7 +45,9 @@ def generate_text(prompt, max_tokens, temperature):
41
  "max_tokens": max_tokens,
42
  "temperature": temperature,
43
  }
44
- response = requests.post("https://api.groq.com/openai/v1/chat/completions", headers={"Authorization": "Bearer YOUR_GROQ_TOKEN"}, json=payload)
 
 
45
  if response.status_code == 200:
46
  result = response.json()
47
  return result["choices"][0]["message"]["content"]
@@ -82,10 +88,10 @@ if st.sidebar.button("Submit"):
82
 
83
  # Guide section
84
  if st.sidebar.button("How to Use"):
85
- st.sidebar.write("""
86
- ### How to Use This App
87
- 1. **Enter Tamil Text**: Type or paste the Tamil text you want to translate.
88
- 2. **Adjust Settings**: Use the sliders to set the maximum tokens for text generation and the temperature for creativity.
89
- 3. **Submit**: Click the Submit button to generate translations, images, and stories.
90
- 4. **View Results**: Check the translated text, generated image, and story in the main area.
91
  """)
 
1
+ import os
2
  import streamlit as st
3
  import requests
4
  import json
 
7
  import numpy as np
8
  from io import BytesIO
9
 
10
+ # Load tokens from environment variables
11
+ HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
12
+ GROQ_TOKEN = os.getenv("GROQ_TOKEN")
13
+
14
+ # Hugging Face API URLs
15
  TRANSLATE_API_URL = "https://api-inference.huggingface.co/models/facebook/mbart-large-50-many-to-one-mmt"
16
  IMAGE_API_URL = "https://api-inference.huggingface.co/models/CompVis/stable-diffusion-v1-4"
 
17
  headers = {"Authorization": f"Bearer {HUGGINGFACE_TOKEN}"}
18
 
19
  # Function to translate Tamil to English
 
45
  "max_tokens": max_tokens,
46
  "temperature": temperature,
47
  }
48
+ response = requests.post("https://api.groq.com/openai/v1/chat/completions",
49
+ headers={"Authorization": f"Bearer {GROQ_TOKEN}"},
50
+ json=payload)
51
  if response.status_code == 200:
52
  result = response.json()
53
  return result["choices"][0]["message"]["content"]
 
88
 
89
  # Guide section
90
  if st.sidebar.button("How to Use"):
91
+ st.sidebar.write("""
92
+ ### How to Use This App
93
+ 1. **Enter Tamil Text**: Type or paste the Tamil text you want to translate.
94
+ 2. **Adjust Settings**: Use the sliders to set the maximum tokens for text generation and the temperature for creativity.
95
+ 3. **Submit**: Click the Submit button to generate translations, images, and stories.
96
+ 4. **View Results**: Check the translated text, generated image, and story in the main area.
97
  """)