vikigitonga11 commited on
Commit
1798899
·
verified ·
1 Parent(s): b282d46

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -13,16 +13,21 @@ def generate_paraphrase(text, temperature):
13
  # Limit input to 700 words
14
  words = text.split()
15
  if len(words) > 700:
16
- return "⚠️ Please enter a maximum of 700 words."
 
 
 
 
 
 
 
 
17
 
18
- result = paraphrase_pipeline(
19
- text,
20
- temperature=temperature, # Adds randomness to prevent repetition
21
- top_k=50, # Consider top-k tokens for variation
22
- do_sample=True # Enable sampling
23
- )
24
 
25
- return result[0]["generated_text"]
 
26
 
27
  # Define Gradio Interface
28
  description = """
@@ -45,4 +50,5 @@ demo = gr.Interface(
45
  live=True,
46
  )
47
 
48
- demo.launch()
 
 
13
  # Limit input to 700 words
14
  words = text.split()
15
  if len(words) > 700:
16
+ return "⚠️ Input too long! Please enter a maximum of 700 words."
17
+
18
+ try:
19
+ result = paraphrase_pipeline(
20
+ text,
21
+ temperature=temperature, # Adds randomness to prevent repetition
22
+ top_k=50, # Consider top-k tokens for variation
23
+ do_sample=True # Enable sampling
24
+ )
25
 
26
+ # Ensure correct output formatting
27
+ return result[0].get("generated_text", "⚠️ Paraphrasing failed. Please try again.")
 
 
 
 
28
 
29
+ except Exception as e:
30
+ return f"⚠️ An error occurred: {str(e)}"
31
 
32
  # Define Gradio Interface
33
  description = """
 
50
  live=True,
51
  )
52
 
53
+ if __name__ == "__main__":
54
+ demo.launch()