sanketshinde3001 commited on
Commit
6c89158
·
verified ·
1 Parent(s): 75ac32c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -29,10 +29,11 @@ app.add_middleware(
29
  allow_headers=["*"], # Allows all headers
30
  )
31
 
32
- # Load NLP models
 
33
  try:
34
- # Load text humanization model
35
  humanize_pipe = pipeline("text2text-generation", model="danibor/flan-t5-base-humanizer")
 
36
 
37
  # Load spaCy model
38
  nlp = spacy.load("en_core_web_sm")
@@ -42,7 +43,7 @@ try:
42
 
43
  print("All NLP models loaded successfully!")
44
  except Exception as e:
45
- print(f"Error loading models: {e}")
46
  # Create fallback functions if models fail to load
47
  def mock_function(text):
48
  return "Model could not be loaded. This is a fallback response."
@@ -74,6 +75,9 @@ async def humanize_text(request: TextRequest):
74
 
75
  try:
76
  # Generate humanized text
 
 
 
77
  result = humanize_pipe(input_text, max_length=500, do_sample=True)
78
  humanized_text = result[0]['generated_text']
79
 
 
29
  allow_headers=["*"], # Allows all headers
30
  )
31
 
32
+ humanize_pipe = None # Default to None before trying to load
33
+
34
  try:
 
35
  humanize_pipe = pipeline("text2text-generation", model="danibor/flan-t5-base-humanizer")
36
+ print("Humanization model loaded successfully!")
37
 
38
  # Load spaCy model
39
  nlp = spacy.load("en_core_web_sm")
 
43
 
44
  print("All NLP models loaded successfully!")
45
  except Exception as e:
46
+ print(f"Error loading humanization model: {e}")
47
  # Create fallback functions if models fail to load
48
  def mock_function(text):
49
  return "Model could not be loaded. This is a fallback response."
 
75
 
76
  try:
77
  # Generate humanized text
78
+ if humanize_pipe is None:
79
+ raise HTTPException(status_code=500, detail="Humanization model is not loaded.")
80
+
81
  result = humanize_pipe(input_text, max_length=500, do_sample=True)
82
  humanized_text = result[0]['generated_text']
83