Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import os | |
| from dotenv import load_dotenv | |
| from groq import Groq | |
| # Load API Key | |
| load_dotenv() | |
| client = Groq(api_key=os.getenv("GROQ_API_KEY")) | |
| # Summarization Prompt Template | |
| def summarize_terms(text): | |
| if not text.strip(): | |
| return "Please enter or upload some Terms & Conditions text." | |
| prompt = f""" | |
| 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. | |
| Terms & Conditions: | |
| {text} | |
| Summarize: | |
| """ | |
| try: | |
| response = client.chat.completions.create( | |
| model="llama3-8b-8192", | |
| messages=[{"role": "user", "content": prompt}], | |
| temperature=0.3, | |
| ) | |
| return response.choices[0].message.content.strip() | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| # File Input Handler | |
| def handle_inputs(text_input, file): | |
| if file: | |
| text = file.read().decode("utf-8") | |
| else: | |
| text = text_input | |
| return summarize_terms(text) | |
| # Gradio Interface | |
| with gr.Blocks(title="T&C Summarizer Chatbot") as demo: | |
| gr.Markdown("## ๐ Terms & Conditions Summarizer\nSummarize complex legal T&C into clear bullet points using LLaMA 3 by Groq.") | |
| with gr.Row(): | |
| text_input = gr.Textbox(lines=10, label="Paste Terms & Conditions") | |
| file_input = gr.File(label="Or Upload a .txt File", file_types=[".txt"]) | |
| summarize_button = gr.Button("Summarize") | |
| output = gr.Textbox(label="Summarized Points", lines=10) | |
| summarize_button.click(fn=handle_inputs, inputs=[text_input, file_input], outputs=output) | |
| if __name__ == "__main__": | |
| demo.launch() | |