Commit 2a087a53 authored by Lelkada L L P S M's avatar Lelkada L L P S M

content filtration screen

parent f54b02c8
from flask import request
from pymongo import MongoClient
def check_word_safety(word):
client = MongoClient("mongodb+srv://xxxx:xxxx@cluster0.kddddr.mongodb.net")
db = client['word_filtration']
blacklist_col = db['blacklist']
whitelist_col = db['whitelist']
moderate_col = db['moderate']
# Check if the word exists in the blacklist
if blacklist_col.find_one({"word": word}):
return "unsafe"
# Check if the word exists in the whitelist
whitelist_entry = whitelist_col.find_one({"word": word})
if whitelist_entry:
sensitive_score = whitelist_entry.get("sensitive_score")
if sensitive_score == 1:
return "safe"
else:
return "unsafe"
# If the word does not exist in the whitelist
moderate_col.insert_one({"word": word, "status": "not_verified"})
return "not_verified"
......@@ -6,31 +6,12 @@ from flask_cors import CORS
from word_card_game import wordGameData
from word_generation import get_similar_words
from flip_card_content import getFlipCardContent
from content_filtration import check_word_safety
app = Flask(__name__)
#### Load pretrained models here ####
#model1 = pickle.load(open('model1.pkl','rb'))
# send a json {'exp':1.8,} as a post request to make a prediction
'''
@app.route('/api/predict',methods=['POST'])
def predict():
data = request.get_json(force=True)
prediction = model1.predict([[np.array(data['exp'])]])
output = prediction[0]
return jsonify(output)
#path to check server status
@app.route("/")
def default_get():
return "<p>HereMe Backend !</p>"
'''
@app.route('/api/word-game', methods=['GET'])
def word_game_api():
w1 = request.args.get('w1')
......@@ -63,6 +44,16 @@ def get_images_data():
images_data = wordGameData()
return jsonify(images_data)
@app.route('/check_word', methods=['POST'])
def check_word():
data = request.get_json()
word = data.get('word')
if not word:
return jsonify({"error": "No word provided"}), 400
result = check_word_safety(word)
return jsonify({"word": word, "status": result}), 200
if __name__ == '__main__':
CORS(app.run(host='0.0.0.0', port=5000, debug=True))
#app.run(host='0.0.0.0', port=5000, debug=True)
\ No newline at end of file
......@@ -10,6 +10,7 @@ import ProgressMapScreen from './screens/ProgressMapScreen';
import WordGameScreen from './screens/WordGameScreen';
import PhoneticWordScreen from './screens/PhoneticWordsScreen';
import FlipCardGameScreen from './screens/FlipCardGameScreen';
import ContentFiltration from './screens/ContentFiltrationScreen';
const MainStack = createStackNavigator(
{
......@@ -40,6 +41,9 @@ const MainStack = createStackNavigator(
FlipCardGame: {
screen: FlipCardGameScreen,
},
ContentFiltration: {
screen: ContentFiltration,
},
},
{
initialRouteName: 'Login',
......
import React, { useState } from 'react';
import { StyleSheet, Text, View, TextInput, Button, Alert } from 'react-native';
import axios from 'axios';
export default function ContentFiltration() {
const [word, setWord] = useState('');
const [response, setResponse] = useState('');
const checkWord = async () => {
try {
const result = await axios.post('http://192.168.137.111:5000/check_word', {
word: word,
});
setResponse(result.data.status);
} catch (error) {
Alert.alert('Error', 'An error occurred while checking the word.');
}
};
return (
<View style={styles.container}>
<TextInput
style={styles.input}
onChangeText={setWord}
value={word}
placeholder="Enter a word"
/>
<Button title="Check" onPress={checkWord} />
{response ? <Text style={styles.response}>Status: {response}</Text> : null}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingHorizontal: 16,
},
input: {
height: 40,
borderColor: 'gray',
borderWidth: 1,
marginBottom: 16,
},
response: {
marginTop: 16,
},
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment