agusrajuthaliyan commited on
Commit
b36bb28
Β·
verified Β·
1 Parent(s): 1fe472d

Upload 4 files

Browse files
Files changed (4) hide show
  1. .gitignore +3 -0
  2. README.md +49 -13
  3. app.py +57 -0
  4. 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
- title: Terms Analyzer
3
- emoji: πŸ“‰
4
- colorFrom: indigo
5
- colorTo: gray
6
- sdk: gradio
7
- sdk_version: 5.32.1
8
- app_file: app.py
9
- pinned: false
10
- short_description: Summarizes Terms and Conditions for users
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # πŸ“ Terms & Conditions Summarizer Chatbot
2
+
3
+ ![Python](https://img.shields.io/badge/Python-3.10-blue.svg)
4
+ ![Gradio](https://img.shields.io/badge/Gradio-4.26.0-lightgrey.svg)
5
+ ![Groq](https://img.shields.io/badge/Groq-0.8.0-blueviolet.svg)
6
+ ![LLaMA-3](https://img.shields.io/badge/LLaMA--3-v3.1-orange.svg)
7
+ ![python-dotenv](https://img.shields.io/badge/python--dotenv-1.0.0-informational.svg)
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