FESG1234 commited on
Commit
6ea3825
·
verified ·
1 Parent(s): ae63ae0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -3,6 +3,28 @@ import torch
3
  from transformers import pipeline
4
  import gradio as gr
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  # Initialize the pipeline
7
  pipe = pipeline(
8
  "text-generation",
 
3
  from transformers import pipeline
4
  import gradio as gr
5
 
6
+ import os
7
+
8
+
9
+ def init_huggingface_auth():
10
+ """
11
+ Initialize Hugging Face authentication in a Space environment
12
+ """
13
+ token = os.environ.get('HUGGINGFACE_TOKEN')
14
+ if token:
15
+ try:
16
+ login(token=token)
17
+ print("Successfully logged in to Hugging Face!")
18
+ except Exception as e:
19
+ print(f"Error during login: {str(e)}")
20
+ return False
21
+ else:
22
+ print("No Hugging Face token found in environment variables")
23
+ return False
24
+ return True
25
+
26
+ if not init_huggingface_auth():
27
+ print("Warning: Hugging Face authentication failed")
28
  # Initialize the pipeline
29
  pipe = pipeline(
30
  "text-generation",