Commit ba4b4997 authored by Lelkada L L P S M's avatar Lelkada L L P S M

minor app changes

parent 2a087a53
...@@ -2,7 +2,7 @@ from flask import request ...@@ -2,7 +2,7 @@ from flask import request
from pymongo import MongoClient from pymongo import MongoClient
def check_word_safety(word): def check_word_safety(word):
client = MongoClient("mongodb+srv://xxxx:xxxx@cluster0.kddddr.mongodb.net") client = MongoClient("mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net")
db = client['word_filtration'] db = client['word_filtration']
blacklist_col = db['blacklist'] blacklist_col = db['blacklist']
whitelist_col = db['whitelist'] whitelist_col = db['whitelist']
...@@ -16,6 +16,7 @@ def check_word_safety(word): ...@@ -16,6 +16,7 @@ def check_word_safety(word):
whitelist_entry = whitelist_col.find_one({"word": word}) whitelist_entry = whitelist_col.find_one({"word": word})
if whitelist_entry: if whitelist_entry:
sensitive_score = whitelist_entry.get("sensitive_score") sensitive_score = whitelist_entry.get("sensitive_score")
print(sensitive_score)
if sensitive_score == 1: if sensitive_score == 1:
return "safe" return "safe"
else: else:
......
import pymongo import pymongo
def getFlipCardContent(): def getFlipCardContent():
client = pymongo.MongoClient("mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net") client = pymongo.MongoClient("mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net")
db = client['word_card'] db = client['word_card']
collection = db['card'] collection = db['card']
......
import torch import torch
from transformers import RobertaTokenizer, RobertaForMaskedLM from transformers import RobertaTokenizer, RobertaForMaskedLM
import pymongo import pymongo
import random
# Load the pretrained RoBERTa model and tokenizer # Load the pretrained RoBERTa model and tokenizer
tokenizer = RobertaTokenizer.from_pretrained('roberta-base') tokenizer = RobertaTokenizer.from_pretrained('roberta-base')
model = RobertaForMaskedLM.from_pretrained('roberta-base') model = RobertaForMaskedLM.from_pretrained('roberta-base')
def get_similar_words(input_word, top_k=3): 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 # Create a masked sentence with the input word
masked_sentence = f"The {input_word} is related to the {tokenizer.mask_token}." 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): ...@@ -39,14 +53,14 @@ def get_similar_words(input_word, top_k=3):
#connect mongo #connect mongo
client = pymongo.MongoClient("mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net") client = pymongo.MongoClient("mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net")
db = client['word_card'] db_1 = client['word_card']
collection = db['card'] collection_1 = db_1['card']
document = {"card_0": result} document = {"card_0": result}
print('---------------') #print('---------------')
print(document) #print(document)
collection.delete_many({}) collection_1.delete_many({})
collection.insert_one(document) collection_1.insert_one(document)
return result return result
...@@ -10,5 +10,6 @@ expo install react-native-svg ...@@ -10,5 +10,6 @@ expo install react-native-svg
### Start app ### Start app
expo start expo start
\ No newline at end of file
import React, { useState } from 'react'; import React, { useState } from 'react';
import { StyleSheet, Text, View, TextInput, Button, Alert } from 'react-native'; import { StyleSheet, Text, View, TextInput, Button, Alert } from 'react-native';
import axios from 'axios';
export default function ContentFiltration() { export default function ContentFiltration() {
const [word, setWord] = useState(''); const [word, setWord] = useState('');
...@@ -8,15 +7,24 @@ export default function ContentFiltration() { ...@@ -8,15 +7,24 @@ export default function ContentFiltration() {
const checkWord = async () => { const checkWord = async () => {
try { try {
const result = await axios.post('http://192.168.137.111:5000/check_word', { const response = await fetch('http://192.168.1.83:5000/check_word', {
word: word, method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ word: word }),
}); });
setResponse(result.data.status);
if (!response.ok) {
throw new Error('An error occurred while checking the word.');
}
const result = await response.json();
setResponse(result.status);
} catch (error) { } catch (error) {
Alert.alert('Error', 'An error occurred while checking the word.'); Alert.alert('Error', error.message);
} }
}; };
return ( return (
<View style={styles.container}> <View style={styles.container}>
<TextInput <TextInput
......
...@@ -112,7 +112,7 @@ export default function FlipCardGame() { ...@@ -112,7 +112,7 @@ export default function FlipCardGame() {
const fetchImagesData = async () => { const fetchImagesData = async () => {
try { 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(); const data = await response.json();
//console.log(data); //console.log(data);
......
...@@ -27,6 +27,11 @@ const HomeScreen = ({ navigation }) => { ...@@ -27,6 +27,11 @@ const HomeScreen = ({ navigation }) => {
<Image source={require('./assets/home/balloon.png')} style={styles.buttonImage} resizeMode="cover" /> <Image source={require('./assets/home/balloon.png')} style={styles.buttonImage} resizeMode="cover" />
<Text style={styles.buttonText}>Learn</Text> <Text style={styles.buttonText}>Learn</Text>
</TouchableOpacity> </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> </View>
); );
}; };
...@@ -108,6 +113,20 @@ const styles = StyleSheet.create({ ...@@ -108,6 +113,20 @@ const styles = StyleSheet.create({
textShadowOffset: { width: -1, height: 1 }, textShadowOffset: { width: -1, height: 1 },
textShadowRadius: 10, 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; export default HomeScreen;
...@@ -20,7 +20,7 @@ const screenHeight = Dimensions.get("window").height; ...@@ -20,7 +20,7 @@ const screenHeight = Dimensions.get("window").height;
const fetchCards = async () => { const fetchCards = async () => {
try { try {
const response = await fetch('http://192.168.137.111:5000/api/similar-words?word=cat'); const response = await fetch('http://192.168.1.86:5000/api/similar-words?word=cat');
const data = await response.json(); const data = await response.json();
//console.log(data) //console.log(data)
return data.similar_words; 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