indhupamula commited on
Commit
1547aeb
Β·
verified Β·
1 Parent(s): b2c7949

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -9
app.py CHANGED
@@ -1,35 +1,50 @@
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())
 
1
  import streamlit as st
2
  import requests
3
 
4
+ HF_BACKEND_URL = "https://your-backend-url.hf.space" # Update with your backend link
5
 
6
  st.title("πŸš€ Plagiarism & AI Detector")
7
 
8
+ # Function to safely call API
9
+ def fetch_api_response(url, params=None, files=None):
10
+ try:
11
+ if files:
12
+ response = requests.post(url, files=files)
13
+ else:
14
+ response = requests.post(url, params=params)
15
+
16
+ if response.status_code == 200:
17
+ return response.json()
18
+ else:
19
+ return {"error": f"API Error: {response.status_code} - {response.text}"}
20
+ except requests.exceptions.RequestException as e:
21
+ return {"error": f"Request Failed: {str(e)}"}
22
+
23
  # Text Plagiarism
24
  st.subheader("πŸ” Check Text Plagiarism")
25
  text = st.text_area("Enter text to check for plagiarism")
26
  if st.button("Check Plagiarism"):
27
+ result = fetch_api_response(f"{HF_BACKEND_URL}/check_text", params={"text": text})
28
+ st.json(result)
29
 
30
  # Code Plagiarism
31
  st.subheader("πŸ’» Check Code Plagiarism")
32
  code = st.text_area("Paste code to check plagiarism")
33
  if st.button("Check Code Plagiarism"):
34
+ result = fetch_api_response(f"{HF_BACKEND_URL}/check_code", params={"code": code})
35
+ st.json(result)
36
 
37
  # AI Detection
38
  st.subheader("πŸ€– Detect AI-Generated Content")
39
  ai_text = st.text_area("Enter text to check AI detection")
40
  if st.button("Detect AI"):
41
+ result = fetch_api_response(f"{HF_BACKEND_URL}/detect_ai", params={"text": ai_text})
42
+ st.json(result)
43
 
44
  # PDF Upload
45
  st.subheader("πŸ“‚ Upload PDF for Plagiarism Check")
46
  pdf = st.file_uploader("Upload a PDF file", type=["pdf"])
47
  if pdf:
48
  files = {"file": pdf.getvalue()}
49
+ result = fetch_api_response(f"{HF_BACKEND_URL}/upload_pdf", files=files)
50
+ st.json(result)