Commit c9a5f148 authored by Esala Senrathna's avatar Esala Senrathna

fixing rebase conflicts

parent 988edf75
......@@ -4,6 +4,7 @@ import logging
import speech_recognition as sr
from flask import Flask, request, jsonify, request
from flask_cors import CORS
import pymongo
#import pickle
from word_card_game import wordGameData
......@@ -11,6 +12,10 @@ from word_generation import get_similar_words
from flip_card_content import getFlipCardContent
from pydub import AudioSegment
client = pymongo.MongoClient("mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net")
db = client['word_filtration']
moderate_collection = db['moderate']
whitelist_collection = db['whitelist']
app = Flask(__name__)
......@@ -71,11 +76,21 @@ def get_images_data():
def get_audio_data():
logging.info("File received")
# check if the post request has the file part
if 'audio' not in request.files:
return 'No file part'
file = request.files['audio']
result = check_word_safety(word)
return jsonify({"word": word, "status": result}), 200
@app.route('/api/moderate-words', methods=['GET'])
def get_words():
words = moderate_collection.find().limit(10)
return jsonify(words=[word['word'] for word in words])
@app.route('/api/moderate-handle-word', methods=['POST'])
def handle_word():
word = request.json.get('word')
score = request.json.get('score')
moderate_collection.delete_one({'word': word})
whitelist_collection.insert_one({'word': word, 'sensitivity_score': score})
return jsonify(success=True)
# if user does not select file, browser also
# submit an empty part without filename
......
......@@ -7,6 +7,22 @@ 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()
count = collection_0.estimated_document_count()
random_skip = random.randint(0, count - 1)
random_word = collection_0.find().skip(random_skip).next()['object']
input_word = random_word.strip()
print('---------------------------------------------------------')
print('')
print("Input word = "+input_word)
# Create a masked sentence with the input word
masked_sentence = f"The {input_word} is related to the {tokenizer.mask_token}."
......
......@@ -17,6 +17,8 @@ import ContentFiltration from './screens/ContentFiltrationScreen';
import SpeechTherapyScreen_1 from './screens/SpeechTherapy_1';
import SpeechTherapyScreen_2 from './screens/SpeechTherapy_2';
import ScoreScreen from './screens/ScoreScreen';
import PinEntryScreen from './screens/PinEntryScreen';
import ContentModeration from './screens/ContentModerationScreen';
const MainStack = createStackNavigator(
{
......@@ -59,6 +61,12 @@ const MainStack = createStackNavigator(
ScoreScreen: {
screen: ScoreScreen,
},
PinEntry: {
screen: PinEntryScreen,
},
ContentModeration: {
screen: ContentModeration,
},
},
{
initialRouteName: 'Login',
......
This diff is collapsed.
......@@ -12,7 +12,7 @@
"@expo/vector-icons": "^13.0.0",
"@react-navigation/native": "^6.1.6",
"@react-navigation/stack": "^6.3.16",
"axios": "^1.3.6",
"axios": "^1.4.0",
"expo": "~48.0.9",
"expo-linking": "^4.0.1",
"expo-av": "~13.2.1",
......@@ -20,11 +20,14 @@
"expo-file-system": "~15.2.2",
"expo-screen-orientation": "~5.1.1",
"expo-status-bar": "~1.4.4",
"mongodb": "^5.5.0",
"react": "18.2.0",
"react-native": "^0.71.6",
"react-native-draggable": "^3.3.0",
"react-native-draggable-flatlist": "^4.0.1",
"react-native-elements": "^3.4.3",
"react-native-gesture-handler": "~2.9.0",
"react-native-numeric-input": "^1.9.1",
"react-native-orientation-locker": "^1.5.0",
"react-native-reanimated": "~2.14.4",
"react-native-safe-area-context": "4.5.0",
......
import React, { useState } from 'react';
import { StyleSheet, Text, View, TextInput, Button, Alert } from 'react-native';
import { StyleSheet, Text, View, TextInput, Button, Alert, ActivityIndicator } from 'react-native';
export default function ContentFiltration() {
const [word, setWord] = useState('');
const [response, setResponse] = useState('');
const [loading, setLoading] = useState(false);
const checkWord = async () => {
setLoading(true);
try {
const response = await fetch('http://192.168.17.111:5000/check_word', {
const response = await fetch('http://192.168.8.194:5000/check_word', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
......@@ -23,8 +25,11 @@ export default function ContentFiltration() {
setResponse(result.status);
} catch (error) {
Alert.alert('Error', error.message);
} finally {
setLoading(false);
}
};
return (
<View style={styles.container}>
<TextInput
......@@ -34,7 +39,11 @@ export default function ContentFiltration() {
placeholder="Enter a word"
/>
<Button title="Check" onPress={checkWord} />
{response ? <Text style={styles.response}>Status: {response}</Text> : null}
{loading ? (
<ActivityIndicator size="large" color="#0000ff" />
) : response ? (
<Text style={styles.response}>Status: {response}</Text>
) : null}
</View>
);
}
......
import React, { useEffect, useState } from 'react';
import { View, Text, Button, ImageBackground, StyleSheet, ScrollView } from 'react-native';
import axios from 'axios';
const ContentModerationScreen = ({ navigation }) => {
const [words, setWords] = useState([]);
useEffect(() => {
fetchWords();
}, []);
const fetchWords = async () => {
try {
const res = await axios.get('http://192.168.8.194:5000/api/moderate-words');
setWords(res.data.words);
} catch (error) {
console.error(error);
}
};
const handleWord = async (word, score) => {
try {
await axios.post('http://192.168.8.194:5000/api/moderate-handle-word', { word, score });
setWords(words.filter(w => w !== word));
} catch (error) {
console.error(error);
}
};
return (
<ImageBackground source={require('./assets/home/home_bg.png')} style={styles.background}>
<Text style={styles.title}>Mark safe words</Text>
<View style={styles.wordListBox} />
<View style={styles.overlay}>
<ScrollView contentContainerStyle={styles.wordList}>
{words.map((word, index) => (
<View key={index} style={styles.wordContainer}>
<Text style={styles.word}>{word}</Text>
<View style={styles.buttonContainer}>
<Button title="Safe" color="green" onPress={() => handleWord(word, 1)} />
<Button title="Unsafe" color="red" onPress={() => handleWord(word, -1)} />
</View>
</View>
))}
</ScrollView>
</View>
<View style={styles.demoButton}>
<Button title="OPEN DEMO" onPress={() => navigation.navigate('ContentFiltration')} />
</View>
</ImageBackground>
);
};
const styles = StyleSheet.create({
background: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 20,
},
title: {
fontSize: 24,
fontWeight: 'bold',
position: 'absolute',
top: 10,
alignSelf: 'center',
top:100
},
wordListBox: {
backgroundColor: '#fff',
opacity: 0.5,
borderRadius: 20,
height: '60%',
width: '100%',
marginTop: 50,
marginBottom: 70,
position: 'absolute',
},
overlay: {
marginTop: 50,
marginBottom: 70,
width: '100%',
height: '60%',
},
wordList: {
width: '90%',
top:50,
left:20
},
wordContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
width: '100%',
marginBottom: 20,
},
buttonContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
width: '40%',
left: 5,
right: 5
},
word: {
fontSize: 28,
},
demoButton: {
position: 'absolute',
bottom: 40,
width: '100%',
},
});
export default ContentModerationScreen;
......@@ -42,7 +42,7 @@ const Card = ({ image, audio, onFlip, gameOver, correct, soundRef }) => {
style={[styles.card, correct && gameOver ? styles.correctCard : null]}
onPress={handleFlip}
>
<Image source={isFlipped ? image : require('./assets/ST/owl.png')} style={styles.cardImage} />
<Image source={isFlipped ? image : require('./assets/FC/card_back.png')} style={styles.cardImage} />
</TouchableOpacity>
);
};
......@@ -112,7 +112,7 @@ export default function FlipCardGame() {
const fetchImagesData = async () => {
try {
const response = await fetch('http://192.168.17.111:5000/api/images_data');
const response = await fetch('http://192.168.8.194:5000/api/images_data');
const data = await response.json();
//console.log(data);
......
......@@ -48,6 +48,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('PinEntry')}>
<Image source={require('./assets/settings_icon.png')} style={styles.buttonImage} resizeMode="cover" />
<Text style={styles.buttonTextCensor}>Censor</Text>
</TouchableOpacity>
</View>
);
};
......
import React, { useState, useRef } from 'react';
import { View, Text, ImageBackground, Keyboard, StyleSheet } from 'react-native';
import { Input } from 'react-native-elements';
const PinEntryScreen = ({ navigation }) => {
const [pin, setPin] = useState(['', '', '', '']);
const refs = Array(4).fill(0).map((_, i) => useRef(null));
const onChange = (index, value) => {
if (value.length > 1) {
return;
}
const newPin = [...pin];
newPin[index] = value;
setPin(newPin);
if (value !== '') {
if (index < 3) {
refs[index + 1].current.focus();
}
}
if (newPin.join('') === '1122') {
Keyboard.dismiss();
navigation.navigate('ContentModeration');
}
};
return (
<ImageBackground source={require('./assets/home/home_bg.png')} style={styles.background}>
<Text style={styles.title}>Enter Pin</Text>
<View style={styles.inputContainer}>
{pin.map((p, i) => (
<Input
key={i}
ref={refs[i]}
value={p}
keyboardType='numeric'
onChangeText={(value) => onChange(i, value)}
maxLength={1}
containerStyle={styles.input}
inputContainerStyle={{ borderBottomWidth: 0 }}
/>
))}
</View>
</ImageBackground>
);
};
const styles = StyleSheet.create({
background: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
title: {
fontSize: 24,
marginBottom: 20,
},
inputContainer: {
flexDirection: 'row',
justifyContent: 'center',
},
input: {
width: 50,
height: 50,
backgroundColor: '#fff',
borderRadius: 5,
margin: 5,
},
});
export default PinEntryScreen;
......@@ -20,7 +20,7 @@ const screenHeight = Dimensions.get("window").height;
const fetchCards = async () => {
try {
const response = await fetch('http://192.168.17.111:5000/api/similar-words?word=cat');
const response = await fetch('http://192.168.8.194:5000/api/similar-words?word=cat');
const data = await response.json();
//console.log(data)
return data.similar_words;
......
This diff is collapsed.
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