VoltIC commited on
Commit
99745c9
·
verified ·
1 Parent(s): e96e040

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -2,22 +2,21 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
5
- # 1. Setup the Client
6
- # It will use the HF_TOKEN if you set it as a Secret,
7
- # otherwise it works automatically if the model is Public.
8
  model_id = "VoltIC/Automated-Text-Summarizer"
9
  client = InferenceClient(model=model_id, token=os.getenv("HF_TOKEN"))
10
 
11
  def summarize_text(text):
12
- if not text.strip():
13
- return "Please enter text to summarize."
14
-
15
  try:
16
- # This calls the model remotely (No 1.63GB download needed!)
17
- output = client.summarization(text)
18
- return output
 
 
 
 
19
  except Exception as e:
20
- return f"Error: {str(e)}. Tip: Ensure model is Public or HF_TOKEN is set."
21
 
22
  # 2. Simplified Interface to avoid the IndexError
23
  with gr.Blocks() as app:
 
2
  from huggingface_hub import InferenceClient
3
  import os
4
 
 
 
 
5
  model_id = "VoltIC/Automated-Text-Summarizer"
6
  client = InferenceClient(model=model_id, token=os.getenv("HF_TOKEN"))
7
 
8
  def summarize_text(text):
9
+ input_len = len(text.split())
 
 
10
  try:
11
+ summary = client.summarization(text)
12
+ output_len = len(summary.split())
13
+
14
+ # Calculate reduction %
15
+ reduction = round((1 - output_len/input_len) * 100)
16
+
17
+ return f"{summary}\n\n---\n📊 Compression: {reduction}% (Reduced from {input_len} to {output_len} words)"
18
  except Exception as e:
19
+ return f"Error: {e}"
20
 
21
  # 2. Simplified Interface to avoid the IndexError
22
  with gr.Blocks() as app: