Commit 51c952f1 authored by Lelkada L L P S M's avatar Lelkada L L P S M

Merge branch 'it19001708' into 'master'

It19001708

See merge request !19
parents e8bd9aa3 ba4b4997
from flask import request
from pymongo import MongoClient
def check_word_safety(word):
client = MongoClient("mongodb+srv://hearme:hearme678@cluster0.kz66vdr.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")
print(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"
import pymongo
def getFlipCardContent():
client = pymongo.MongoClient("mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net")
db = client['word_card']
collection = db['card']
......
......@@ -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
import torch
from transformers import RobertaTokenizer, RobertaForMaskedLM
import pymongo
import random
# Load the pretrained RoBERTa model and tokenizer
tokenizer = RobertaTokenizer.from_pretrained('roberta-base')
model = RobertaForMaskedLM.from_pretrained('roberta-base')
def get_similar_words(input_word, top_k=3):
print(input_word)
#connect to mongoDB
client = pymongo.MongoClient("mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net")
db_0 = client['vocabulary']
collection_0 = db_0['object_expore']
cursor = collection_0.find()
# Print out each document
for document in cursor:
print(document)
random_word = collection_0.aggregate([{'$sample': {'size': 1}}]).next()['object']
input_word = random_word.strip()
print(input_word)
# Create a masked sentence with the input word
masked_sentence = f"The {input_word} is related to the {tokenizer.mask_token}."
......@@ -39,14 +53,14 @@ def get_similar_words(input_word, top_k=3):
#connect mongo
client = pymongo.MongoClient("mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net")
db = client['word_card']
collection = db['card']
db_1 = client['word_card']
collection_1 = db_1['card']
document = {"card_0": result}
print('---------------')
print(document)
#print('---------------')
#print(document)
collection.delete_many({})
collection.insert_one(document)
collection_1.delete_many({})
collection_1.insert_one(document)
return result
......@@ -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',
......
......@@ -10,5 +10,6 @@ expo install react-native-svg
### Start app
expo start
\ No newline at end of file
import React, { useState } from 'react';
import { StyleSheet, Text, View, TextInput, Button, Alert } from 'react-native';
export default function ContentFiltration() {
const [word, setWord] = useState('');
const [response, setResponse] = useState('');
const checkWord = async () => {
try {
const response = await fetch('http://192.168.1.83:5000/check_word', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ word: word }),
});
if (!response.ok) {
throw new Error('An error occurred while checking the word.');
}
const result = await response.json();
setResponse(result.status);
} catch (error) {
Alert.alert('Error', error.message);
}
};
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,
},
});
......@@ -112,7 +112,7 @@ export default function FlipCardGame() {
const fetchImagesData = async () => {
try {
const response = await fetch('http://192.168.137.111:5000/api/images_data');
const response = await fetch('http://192.168.1.86:5000/api/images_data');
const data = await response.json();
//console.log(data);
......
......@@ -27,6 +27,11 @@ const HomeScreen = ({ navigation }) => {
<Image source={require('./assets/home/balloon.png')} style={styles.buttonImage} resizeMode="cover" />
<Text style={styles.buttonText}>Learn</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.buttonsettings} onPress={() => navigation.navigate('ContentFiltration')}>
<Image source={require('./assets/settings_icon.png')} style={styles.buttonImage} resizeMode="cover" />
<Text style={styles.buttonTextCensor}>Censor</Text>
</TouchableOpacity>
</View>
);
};
......@@ -108,6 +113,20 @@ const styles = StyleSheet.create({
textShadowOffset: { width: -1, height: 1 },
textShadowRadius: 10,
},
buttonsettings:{
top:-280,
right:-150,
size:1
},
buttonTextCensor: {
fontSize: 22,
fontWeight: 'bold',
color: 'black',
marginTop: -120,
textShadowOffset: { width: -1, height: 1 },
textShadowRadius: 10,
},
});
export default HomeScreen;
......@@ -4,7 +4,7 @@ import { StyleSheet, Text, View } from 'react-native';
export default function ScreenName() {
return (
<View style={styles.container}>
<Text style={styles.text}>Sample screen</Text>
<Text style={styles.text}>Error: Andriod OS version not compatible</Text>
</View>
);
}
......@@ -12,7 +12,7 @@ export default function ScreenName() {
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#61A6AB',
backgroundColor: '#F1103D',
alignItems: 'center',
justifyContent: 'center',
},
......
......@@ -4,7 +4,7 @@ import { StyleSheet, Text, View } from 'react-native';
export default function ScreenName() {
return (
<View style={styles.container}>
<Text style={styles.text}>Sample screen</Text>
<Text style={styles.text}>Error: Andriod OS version not not compatible</Text>
</View>
);
}
......@@ -12,7 +12,7 @@ export default function ScreenName() {
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#61A6AB',
backgroundColor: '#F1103D',
alignItems: 'center',
justifyContent: 'center',
},
......
......@@ -20,7 +20,7 @@ const screenHeight = Dimensions.get("window").height;
const fetchCards = async () => {
try {
const response = await fetch('http://192.168.137.111:5000/api/similar-words?word=tomato');
const response = await fetch('http://192.168.1.86:5000/api/similar-words?word=cat');
const data = await response.json();
//console.log(data)
return data.similar_words;
......
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