Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import uuid | |
| # Langflow API details | |
| URL = "https://aws-us-east-2.langflow.datastax.com/lf/b2ab904a-f8b6-4852-8986-7a35157bbcea/api/v1/run/820d2db4-35df-4206-9f1b-32facd9da870" | |
| HEADERS = { | |
| "X-DataStax-Current-Org": "9e18b96d-ab61-447d-b25b-0e0a4e0812bd", | |
| "Authorization": "Bearer AstraCS:seCzCQDJWdRXzTSeoHyMJvFB:515563191b0ebed2cc20468c31ac42a2b44d6e5550121b4588d2fbf0df332e47", | |
| "Content-Type": "application/json", | |
| "Accept": "application/json", | |
| } | |
| def ask_dpdp(language, question): | |
| # Enforce language in prompt | |
| prompt = f"Please answer in {language}. {question}" | |
| payload = { | |
| "input_type": "chat", | |
| "output_type": "chat", | |
| "input_value": prompt, | |
| "session_id": str(uuid.uuid4()) | |
| } | |
| try: | |
| response = requests.post(URL, json=payload, headers=HEADERS) | |
| response.raise_for_status() | |
| data = response.json() | |
| return ( | |
| data.get("outputs", [{}])[0] | |
| .get("outputs", [{}])[0] | |
| .get("results", {}) | |
| .get("message", {}) | |
| .get("text", "No response received") | |
| ) | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| # Gradio UI | |
| interface = gr.Interface( | |
| fn=ask_dpdp, | |
| inputs=[ | |
| gr.Dropdown( | |
| choices=["English", "Hindi", "Marathi", "Telugu", "Tamil", "Punjabi"," Gujarati","Bengali", "Kannada", "Malayalam", "Other"] , | |
| value="English", | |
| label="Select Language" | |
| ), | |
| gr.Textbox( | |
| lines=2, | |
| placeholder=( | |
| "Ask anything about DPDP Act... " | |
| "What is DPDP ACT? How is my data protected under DPDP Act?\n" | |
| ) | |
| ) | |
| ], | |
| outputs=gr.Textbox( | |
| lines=8, | |
| label="Answer" | |
| ), | |
| title="📜 DPDP Act Awareness Assistant", | |
| description="### 📘 DPDP Act Awareness Assistant\n\n" | |
| "Ask questions related to **India’s Digital Personal Data Protection (DPDP) Act**.\n\n" | |
| "🔗 **Official Website:** https://www.dpdpa.in/ \n\n" | |
| "🔗 **Official Document:** https://www.meity.gov.in/static/uploads/2024/06/2bf1f0e9f04e6fb4f8fef35e82c42aa5.pdf \n\n" | |
| "🔗 **Official Guidellines 2025 :** https://www.meity.gov.in/static/uploads/2025/11/53450e6e5dc0bfa85ebd78686cadad39.pdf \n\n" | |
| "---\n\n" | |
| "### 🧩 Sample Prompt Templates (You may copy & modify)\n\n" | |
| "🟦 **English** \n" | |
| "➡ *What is DPDP Act?*\n\n" | |
| "🟧 **Marathi** \n" | |
| "➡ *विद्यार्थी म्हणून माझ्यासाठी डिजिटल वैयक्तिक डेटा संरक्षण कायदा कसा उपयुक्त आहे?*\n\n" | |
| "🟩 **Hindi** \n" | |
| "➡ *एक छात्र के रूप में मेरे लिए डिजिटल व्यक्तिगत डेटा संरक्षण अधिनियम कैसे फायदेमंद है?*\n\n" | |
| "🟥 **Tamil** \n" | |
| "➡ *ஒரு மாணவராக எனக்கு டிஜிட்டல் தனிநபர் தரவு பாதுகாப்பு சட்டம் எவ்வாறு பயனுள்ளதாக இருக்கிறது?*\n\n" | |
| "🟪 **Telugu** \n" | |
| "➡ *ఒక విద్యార్థిగా నాకు డిజిటల్ పర్సనల్ డేటా ప్రొటెక్షన్ చట్టం ఎలా ఉపయోగపడుతుంది?*\n\n" | |
| "🟫**Gujrathi** \n" | |
| "➡ *એક વિદ્યાર્થી તરીકે ડિજિટલ પર્સનલ ડેટા પ્રોટેક્શન એક્ટ મારા માટે કેવી રીતે ઉપયોગી છે?*\n\n" | |
| "🟪 **Punjabi** \n" | |
| "➡ *ਇੱਕ ਵਿਦਿਆਰਥੀ ਵਜੋਂ ਮੇਰੇ ਲਈ ਡਿਜੀਟਲ ਪਰਸਨਲ ਡੇਟਾ ਪ੍ਰੋਟੈਕਸ਼ਨ ਐਕਟ ਕਿਵੇਂ ਲਾਭਦਾਇਕ ਹੈ?*\n\n" | |
| "---\n\n" | |
| "💡 *You may also ask any custom question related to the DPDP Act in your selected language.*" | |
| ) | |
| # Launch with public URL | |
| interface.launch(share=True) | |