indhupamula commited on
Commit
f0cd87e
Β·
verified Β·
1 Parent(s): 9381ad2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -37
app.py CHANGED
@@ -1,44 +1,35 @@
1
  import streamlit as st
2
- import os
3
- import numpy as np
4
- import pandas as pd
5
- from sentence_transformers import SentenceTransformer, util
6
 
7
- # Load AI model (BERT)
8
- model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
9
 
10
- # Function to check plagiarism
11
- def check_plagiarism(text, stored_texts):
12
- documents = stored_texts + [text]
13
- embeddings = model.encode(documents, convert_to_tensor=True)
14
- similarity_matrix = util.pytorch_cos_sim(embeddings[-1], embeddings[:-1])
15
-
16
- highest_similarity = np.max(similarity_matrix.numpy())
17
- return highest_similarity * 100
18
 
19
- # Store past documents
20
- if not os.path.exists("database.csv"):
21
- pd.DataFrame(columns=["text"]).to_csv("database.csv", index=False)
22
-
23
- def load_database():
24
- df = pd.read_csv("database.csv")
25
- return df["text"].tolist()
26
 
27
- def save_to_database(text):
28
- df = pd.read_csv("database.csv")
29
- new_df = pd.DataFrame({"text": [text]})
30
- df = pd.concat([df, new_df], ignore_index=True)
31
- df.to_csv("database.csv", index=False)
 
32
 
33
- # Streamlit UI
34
- st.title("Plagiarism Detection System using AI")
35
- input_text = st.text_area("Enter text to check for plagiarism")
 
 
 
36
 
37
- if st.button("Check Plagiarism"):
38
- stored_texts = load_database()
39
- similarity_score = check_plagiarism(input_text, stored_texts)
40
- st.write(f"Plagiarism Score: {similarity_score:.2f}%")
41
-
42
- if similarity_score < 50:
43
- save_to_database(input_text)
44
- st.success("Text added to database for future reference.")
 
1
  import streamlit as st
2
+ import requests
 
 
 
3
 
4
+ HF_BACKEND_URL = "https://your-backend-url.hf.space" # Update this with your backend link
 
5
 
6
+ st.title("πŸš€ Plagiarism & AI Detector")
 
 
 
 
 
 
 
7
 
8
+ # Text Plagiarism
9
+ st.subheader("πŸ” Check Text Plagiarism")
10
+ text = st.text_area("Enter text to check for plagiarism")
11
+ if st.button("Check Plagiarism"):
12
+ response = requests.post(f"{HF_BACKEND_URL}/check_text", params={"text": text})
13
+ st.json(response.json())
 
14
 
15
+ # Code Plagiarism
16
+ st.subheader("πŸ’» Check Code Plagiarism")
17
+ code = st.text_area("Paste code to check plagiarism")
18
+ if st.button("Check Code Plagiarism"):
19
+ response = requests.post(f"{HF_BACKEND_URL}/check_code", params={"code": code})
20
+ st.json(response.json())
21
 
22
+ # AI Detection
23
+ st.subheader("πŸ€– Detect AI-Generated Content")
24
+ ai_text = st.text_area("Enter text to check AI detection")
25
+ if st.button("Detect AI"):
26
+ response = requests.post(f"{HF_BACKEND_URL}/detect_ai", params={"text": ai_text})
27
+ st.json(response.json())
28
 
29
+ # PDF Upload
30
+ st.subheader("πŸ“‚ Upload PDF for Plagiarism Check")
31
+ pdf = st.file_uploader("Upload a PDF file", type=["pdf"])
32
+ if pdf:
33
+ files = {"file": pdf.getvalue()}
34
+ response = requests.post(f"{HF_BACKEND_URL}/upload_pdf", files=files)
35
+ st.json(response.json())