Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +32 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
| 5 |
+
|
| 6 |
+
def analyze_text(text):
|
| 7 |
+
summary = summarizer(text, max_length=150, min_length=40, do_sample=False)[0]["summary_text"]
|
| 8 |
+
follow_ups = [
|
| 9 |
+
"What assumptions are made?",
|
| 10 |
+
"What are potential counterarguments?",
|
| 11 |
+
"What are possible next research questions?"
|
| 12 |
+
]
|
| 13 |
+
return summary, "\n".join(follow_ups)
|
| 14 |
+
|
| 15 |
+
with gr.Blocks() as demo:
|
| 16 |
+
gr.Markdown("### 🧠 Clarity Agent\nPaste text or upload a file to get a summary and follow-up ideas.")
|
| 17 |
+
|
| 18 |
+
with gr.Row():
|
| 19 |
+
input_text = gr.Textbox(label="Paste text", lines=12)
|
| 20 |
+
file_upload = gr.File(label="...or upload .txt/.md", file_types=[".txt", ".md"])
|
| 21 |
+
|
| 22 |
+
submit = gr.Button("Analyze")
|
| 23 |
+
output_summary = gr.Textbox(label="Summary")
|
| 24 |
+
output_questions = gr.Textbox(label="Follow-up Questions")
|
| 25 |
+
|
| 26 |
+
def load_and_analyze(paste, file):
|
| 27 |
+
content = paste or (file.read().decode() if file else "")
|
| 28 |
+
return analyze_text(content) if content.strip() else ("No input provided", "")
|
| 29 |
+
|
| 30 |
+
submit.click(load_and_analyze, inputs=[input_text, file_upload], outputs=[output_summary, output_questions])
|
| 31 |
+
|
| 32 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|