Engr-Saeed commited on
Commit
cc744c0
1 Parent(s): 1b2afbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -31,15 +31,16 @@ def read_document(file):
31
  print(f"Error processing file: {file.name} - {str(e)}")
32
  return f"Error processing file: {file.name} - {str(e)}"
33
 
34
- # Pass your API key directly when initializing the Groq client
35
- api_key = "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" # Replace with your actual API key
 
 
 
36
  client = Groq(api_key=api_key)
37
 
38
  # Function to validate and truncate content to prevent API errors
39
  def validate_content(text):
40
- # Basic validation to remove unwanted characters
41
  validated_text = ''.join(e for e in text if e.isalnum() or e.isspace())
42
- # Truncate text if it's too long
43
  max_length = 8000 # Adjust as needed
44
  if len(validated_text) > max_length:
45
  validated_text = validated_text[:max_length] + "..."
 
31
  print(f"Error processing file: {file.name} - {str(e)}")
32
  return f"Error processing file: {file.name} - {str(e)}"
33
 
34
+ # Retrieve API key from environment variable
35
+ api_key = os.getenv("GROQ_API_KEY") # This assumes you have set the environment variable in Hugging Face Space
36
+ if not api_key:
37
+ raise ValueError("No API key found. Please set the GROQ_API_KEY environment variable.")
38
+
39
  client = Groq(api_key=api_key)
40
 
41
  # Function to validate and truncate content to prevent API errors
42
  def validate_content(text):
 
43
  validated_text = ''.join(e for e in text if e.isalnum() or e.isspace())
 
44
  max_length = 8000 # Adjust as needed
45
  if len(validated_text) > max_length:
46
  validated_text = validated_text[:max_length] + "..."