NikosKprl commited on
Commit
2d6d80e
·
verified ·
1 Parent(s): 91f26a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -34,18 +34,29 @@ else:
34
  model = SentenceTransformer("Lajavaness/bilingual-embedding-large", trust_remote_code=True)
35
 
36
 
37
- api_token = st.text_input("Enter your API key from [GitHub](https://github.com/marketplace/models/azure-openai/gpt-4o):", "Your-API-key", type="password")
 
 
 
 
 
 
 
 
 
38
 
39
  if api_token:
40
- token = os.environ["GITHUB_TOKEN"] = api_token # security reasons
41
  endpoint = "https://models.inference.ai.azure.com"
42
  model_name = "gpt-4o"
43
 
44
- client = OpenAI(
45
- base_url=endpoint,
46
- api_key=token,
47
- )
48
- st.success("API Token set for this session.")
 
 
 
49
  else:
50
  st.warning("Please enter an API token to proceed.")
51
 
 
34
  model = SentenceTransformer("Lajavaness/bilingual-embedding-large", trust_remote_code=True)
35
 
36
 
37
+ api_token = st.text_input("Enter your API key from [GitHub](https://github.com/marketplace/models/azure-openai/gpt-4o):", "", type="password")
38
+
39
+ def validate_token(token, endpoint):
40
+ try:
41
+ headers = {"Authorization": f"Bearer {token}"}
42
+ response = requests.get(f"{endpoint}/models", headers=headers)
43
+ return response.status_code == 200
44
+ except:
45
+ st.error(f"Token validation error: {e}")
46
+ return False
47
 
48
  if api_token:
 
49
  endpoint = "https://models.inference.ai.azure.com"
50
  model_name = "gpt-4o"
51
 
52
+ if validate_token(api_token, endpoint):
53
+ client = OpenAI(
54
+ base_url=endpoint,
55
+ api_key=api_token,
56
+ )
57
+ st.success("API Token is valid and set for this session.")
58
+ else:
59
+ st.error("Invalid API token. Please check and try again.")
60
  else:
61
  st.warning("Please enter an API token to proceed.")
62