Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 13 |
-
return "Please enter text to summarize."
|
| 14 |
-
|
| 15 |
try:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
except Exception as e:
|
| 20 |
-
return f"Error: {
|
| 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:
|