Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- .gitignore +3 -0
- README.md +49 -13
- app.py +57 -0
- requirements.txt +3 -0
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.pyc
|
README.md
CHANGED
|
@@ -1,13 +1,49 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
---
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π Terms & Conditions Summarizer Chatbot
|
| 2 |
+
|
| 3 |
+

|
| 4 |
+

|
| 5 |
+

|
| 6 |
+

|
| 7 |
+

|
| 8 |
+
|
| 9 |
+
A Gradio-based chatbot that reads long and complex Terms & Conditions (T&C) and gives you a simplified summary with just the **key points** using **LLaMA 3** via the **Groq API**.
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
## π Project Overview
|
| 14 |
+
|
| 15 |
+
This app helps users understand lengthy legal documents by providing:
|
| 16 |
+
|
| 17 |
+
- β‘ Fast, AI-generated summaries of T&C content
|
| 18 |
+
- π Support for both **pasted text** and **.txt file uploads**
|
| 19 |
+
- π¬ Summaries written in **bullet points** for clarity
|
| 20 |
+
- π§ Powered by **LLaMA 3** hosted on **Groq** for speed and accuracy
|
| 21 |
+
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
## π§© Features
|
| 25 |
+
|
| 26 |
+
- Accepts raw T&C text via a text box or `.txt` file upload
|
| 27 |
+
- Converts dense legal language into simplified, digestible bullet points
|
| 28 |
+
- Utilizes Groq's blazing-fast inference with LLaMA 3 (8B)
|
| 29 |
+
- Simple and clean Gradio interface
|
| 30 |
+
- Automatically handles both user input modes (text or file)
|
| 31 |
+
|
| 32 |
+
---
|
| 33 |
+
|
| 34 |
+
## π Requirements
|
| 35 |
+
|
| 36 |
+
- Python 3.8+
|
| 37 |
+
- gradio
|
| 38 |
+
- groq
|
| 39 |
+
- python-dotenv
|
| 40 |
+
|
| 41 |
+
---
|
| 42 |
+
|
| 43 |
+
## βοΈ Setup Instructions
|
| 44 |
+
|
| 45 |
+
1. **Clone the repository**
|
| 46 |
+
|
| 47 |
+
```bash
|
| 48 |
+
git clone https://github.com/your-username/terms-summarizer-chatbot.git
|
| 49 |
+
cd terms-summarizer-chatbot
|
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from groq import Groq
|
| 5 |
+
|
| 6 |
+
# Load API Key
|
| 7 |
+
load_dotenv()
|
| 8 |
+
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
| 9 |
+
|
| 10 |
+
# Summarization Prompt Template
|
| 11 |
+
def summarize_terms(text):
|
| 12 |
+
if not text.strip():
|
| 13 |
+
return "Please enter or upload some Terms & Conditions text."
|
| 14 |
+
|
| 15 |
+
prompt = f"""
|
| 16 |
+
You are a legal assistant chatbot. A user has provided the following Terms & Conditions. Your task is to summarize it into a few essential and easy-to-understand bullet points that highlight the most important clauses, limitations, or obligations. Be concise and user-friendly.
|
| 17 |
+
|
| 18 |
+
Terms & Conditions:
|
| 19 |
+
{text}
|
| 20 |
+
|
| 21 |
+
Summarize:
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
response = client.chat.completions.create(
|
| 26 |
+
model="llama3-8b-8192",
|
| 27 |
+
messages=[{"role": "user", "content": prompt}],
|
| 28 |
+
temperature=0.3,
|
| 29 |
+
)
|
| 30 |
+
return response.choices[0].message.content.strip()
|
| 31 |
+
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return f"Error: {str(e)}"
|
| 34 |
+
|
| 35 |
+
# File Input Handler
|
| 36 |
+
def handle_inputs(text_input, file):
|
| 37 |
+
if file:
|
| 38 |
+
text = file.read().decode("utf-8")
|
| 39 |
+
else:
|
| 40 |
+
text = text_input
|
| 41 |
+
return summarize_terms(text)
|
| 42 |
+
|
| 43 |
+
# Gradio Interface
|
| 44 |
+
with gr.Blocks(title="T&C Summarizer Chatbot") as demo:
|
| 45 |
+
gr.Markdown("## π Terms & Conditions Summarizer\nSummarize complex legal T&C into clear bullet points using LLaMA 3 by Groq.")
|
| 46 |
+
|
| 47 |
+
with gr.Row():
|
| 48 |
+
text_input = gr.Textbox(lines=10, label="Paste Terms & Conditions")
|
| 49 |
+
file_input = gr.File(label="Or Upload a .txt File", file_types=[".txt"])
|
| 50 |
+
|
| 51 |
+
summarize_button = gr.Button("Summarize")
|
| 52 |
+
output = gr.Textbox(label="Summarized Points", lines=10)
|
| 53 |
+
|
| 54 |
+
summarize_button.click(fn=handle_inputs, inputs=[text_input, file_input], outputs=output)
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
groq
|
| 3 |
+
python-dotenv
|