Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# 1.
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
except Exception as e:
|
| 11 |
-
pipe = None
|
| 12 |
-
status = f"Error: {str(e)}"
|
| 13 |
|
| 14 |
-
def
|
| 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 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
# 2.
|
| 24 |
with gr.Blocks() as app:
|
| 25 |
-
gr.Markdown("# Aditya's
|
| 26 |
-
gr.Markdown(
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
-
|
| 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()
|