Upload 2 files
Browse files- main.py +38 -0
- requirements.txt +5 -0
main.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from langchain_experimental.data_anonymizer import PresidioAnonymizer, PresidioReversibleAnonymizer
|
3 |
+
from langchain_groq import ChatGroq
|
4 |
+
# from langchain.chat_models import ChatGroq
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
import os
|
7 |
+
# Load environment variables
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
11 |
+
|
12 |
+
# Initialize anonymizer
|
13 |
+
anonymizer = PresidioReversibleAnonymizer()
|
14 |
+
llm = ChatGroq(model_name="llama-3.3-70b-versatile") # Choose an available model
|
15 |
+
|
16 |
+
st.title("Call on Doc Data Anonymization")
|
17 |
+
|
18 |
+
# User Input
|
19 |
+
user_input = st.text_area("Enter your text:", "My name is John Doe and my phone number is 123-456-7890.")
|
20 |
+
|
21 |
+
if st.button("Process"):
|
22 |
+
# Anonymization
|
23 |
+
anonymized_text = anonymizer.anonymize(user_input)
|
24 |
+
st.subheader("1. Original Text:")
|
25 |
+
st.write(user_input)
|
26 |
+
|
27 |
+
st.subheader("2. Anonymized Text:")
|
28 |
+
st.write(anonymized_text)
|
29 |
+
|
30 |
+
# Get LLM response
|
31 |
+
response = llm.predict(anonymized_text)
|
32 |
+
st.subheader("3. LLM Response:")
|
33 |
+
st.write(response)
|
34 |
+
|
35 |
+
# De-anonymization
|
36 |
+
deanonymized_response = anonymizer.deanonymize(response)
|
37 |
+
st.subheader("4. De-anonymized Response:")
|
38 |
+
st.write(deanonymized_response)
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pip install groq langchain langchain-core langchain-community streamlit presidio-analyzer presidio-anonymizer
|
2 |
+
|
3 |
+
pip install langchain-groq
|
4 |
+
|
5 |
+
pip install Faker
|