VoltIC commited on
Commit
e96e040
·
verified ·
1 Parent(s): 45c4e43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -28
app.py CHANGED
@@ -1,41 +1,34 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
  import os
4
 
5
- # 1. Load the model
6
- # NOTE: Ensure your model is PUBLIC on Hugging Face
7
- try:
8
- pipe = pipeline("summarization", model="VoltIC/Automated-Text-Summarizer")
9
- status = "Model loaded successfully!"
10
- except Exception as e:
11
- pipe = None
12
- status = f"Error: {str(e)}"
13
 
14
- def summarize(text):
15
- if pipe is None:
16
- return "Model not available. Check if repo is Public."
17
  if not text.strip():
18
- return "Please enter text."
19
 
20
- result = pipe(text, max_length=130, min_length=30, do_sample=False)
21
- return result[0]['summary_text']
 
 
 
 
22
 
23
- # 2. Build UI using Blocks (Avoids the Interface IndexError)
24
  with gr.Blocks() as app:
25
- gr.Markdown("# Aditya's Automated Text Summarizer")
26
- gr.Markdown(f"**Status:** {status}")
27
 
28
- with gr.Row():
29
- input_text = gr.Textbox(lines=10, label="Input Article", placeholder="Paste text here...")
 
30
 
31
- with gr.Row():
32
- submit_btn = gr.Button("Summarize")
33
-
34
- with gr.Row():
35
- output_text = gr.Textbox(label="Summary")
36
-
37
- submit_btn.click(fn=summarize, inputs=input_text, outputs=output_text)
38
 
39
- # 3. Launch
40
  if __name__ == "__main__":
41
  app.launch()
 
1
  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:
24
+ gr.Markdown("# Aditya's Instant Summarizer")
25
+ gr.Markdown("Uses the HF Inference API to avoid large downloads.")
26
 
27
+ input_box = gr.Textbox(lines=8, label="Input Article")
28
+ output_box = gr.Textbox(label="Summary")
29
+ submit_btn = gr.Button("Summarize")
30
 
31
+ submit_btn.click(fn=summarize_text, inputs=input_box, outputs=output_box)
 
 
 
 
 
 
32
 
 
33
  if __name__ == "__main__":
34
  app.launch()