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

word generation save mongo

parent 6807c444
...@@ -2,3 +2,4 @@ Flask==2.2.3 ...@@ -2,3 +2,4 @@ Flask==2.2.3
numpy==1.24.2 numpy==1.24.2
transformers transformers
torch torch
pymongo
\ No newline at end of file
...@@ -4,6 +4,7 @@ from flask import Flask, request, jsonify, request ...@@ -4,6 +4,7 @@ from flask import Flask, request, jsonify, request
from word_card_game import wordGameData from word_card_game import wordGameData
from word_generation import get_similar_words from word_generation import get_similar_words
from flask_cors import CORS from flask_cors import CORS
import pymongo
app = Flask(__name__) app = Flask(__name__)
......
import torch import torch
from transformers import RobertaTokenizer, RobertaForMaskedLM from transformers import RobertaTokenizer, RobertaForMaskedLM
import pymongo
# 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')
...@@ -35,4 +36,16 @@ def get_similar_words(input_word, top_k=3): ...@@ -35,4 +36,16 @@ def get_similar_words(input_word, top_k=3):
'audio': audio_url 'audio': audio_url
}) })
print(result)
#connect mongo
client = pymongo.MongoClient("mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net")
db = client['word_card']
collection = db['card']
document = {"card_0": result}
collection.delete_many({})
collection.insert_one(document)
return result return result
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
"expo-screen-orientation": "~5.1.1", "expo-screen-orientation": "~5.1.1",
"expo-status-bar": "~1.4.4", "expo-status-bar": "~1.4.4",
"react": "18.2.0", "react": "18.2.0",
"react-native": "^0.71.4", "react-native": "^0.71.6",
"react-native-draggable": "^3.3.0", "react-native-draggable": "^3.3.0",
"react-native-draggable-flatlist": "^4.0.1", "react-native-draggable-flatlist": "^4.0.1",
"react-native-gesture-handler": "~2.9.0", "react-native-gesture-handler": "~2.9.0",
......
...@@ -45,8 +45,32 @@ const MessageBox = ({ visible, onClose }) => { ...@@ -45,8 +45,32 @@ const MessageBox = ({ visible, onClose }) => {
); );
}; };
export default function FlipCardGame() { export default function FlipCardGame({ route }) {
const [gameOver, setGameOver] = useState(false); const [gameOver, setGameOver] = useState(false);
const { cards } = route.params;
console.log(route.params);
const handleScroll = async (event) => {
const newIndex = Math.round(
event.nativeEvent.contentOffset.x / screenWidth
);
if (newIndex !== activeIndex) {
setActiveIndex(newIndex);
if (cards.length > 0) {
await soundRef.current.unloadAsync();
await soundRef.current.loadAsync({ uri: cards[newIndex].audio });
await soundRef.current.playAsync();
}
}
};
const handleAudioPress = async () => {
if (cards.length > 0) {
await soundRef.current.unloadAsync();
await soundRef.current.loadAsync({ uri: cards[activeIndex].audio });
await soundRef.current.playAsync();
}
};
const images = [ const images = [
{ image: require('./assets/CG/content/vegetable.png'), audio: require('./assets/CG/content/vegetable.m4a') }, { image: require('./assets/CG/content/vegetable.png'), audio: require('./assets/CG/content/vegetable.m4a') },
......
...@@ -66,6 +66,7 @@ const SpeechTherapyScreen = ({ navigation }) => { ...@@ -66,6 +66,7 @@ const SpeechTherapyScreen = ({ navigation }) => {
}; };
}, []); }, []);
const updatePlaybackStatus = (status) => { const updatePlaybackStatus = (status) => {
if (status.isLoaded) { if (status.isLoaded) {
setProgress(status.positionMillis / status.durationMillis); setProgress(status.positionMillis / status.durationMillis);
......
...@@ -12,13 +12,13 @@ import { ...@@ -12,13 +12,13 @@ import {
import { Audio } from "expo-av"; import { Audio } from "expo-av";
import { MaterialIcons } from '@expo/vector-icons'; import { MaterialIcons } from '@expo/vector-icons';
import { Ionicons } from '@expo/vector-icons'; import { Ionicons } from '@expo/vector-icons';
import FlipCardGame from "./FlipCardGameScreen";
const screenWidth = Dimensions.get("window").width; const screenWidth = Dimensions.get("window").width;
const screenHeight = Dimensions.get("window").height; const screenHeight = Dimensions.get("window").height;
const fetchCards = async () => { const fetchCards = async () => {
try { try {
console.log("fetch cards 1")
const response = await fetch('http://192.168.216.111:5000/api/similar-words?word=school'); const response = await fetch('http://192.168.216.111:5000/api/similar-words?word=school');
const data = await response.json(); const data = await response.json();
console.log(data) console.log(data)
...@@ -28,11 +28,13 @@ const fetchCards = async () => { ...@@ -28,11 +28,13 @@ const fetchCards = async () => {
} }
}; };
export default function ContentGenerationScreen({ navigation }) { export default function ContentGenerationScreen({ navigation }) {
const [activeIndex, setActiveIndex] = useState(0); const [activeIndex, setActiveIndex] = useState(0);
const [cards, setCards] = useState([]); const [cards, setCards] = useState([]);
const scrollViewRef = useRef(null); const scrollViewRef = useRef(null);
const soundRef = useRef(new Audio.Sound()); const soundRef = useRef(new Audio.Sound());
console.log(cards);
useEffect(() => { useEffect(() => {
const loadCards = async () => { const loadCards = async () => {
...@@ -64,6 +66,7 @@ export default function ContentGenerationScreen({ navigation }) { ...@@ -64,6 +66,7 @@ export default function ContentGenerationScreen({ navigation }) {
await soundRef.current.unloadAsync(); await soundRef.current.unloadAsync();
await soundRef.current.loadAsync({ uri: cards[newIndex].audio }); await soundRef.current.loadAsync({ uri: cards[newIndex].audio });
await soundRef.current.playAsync(); await soundRef.current.playAsync();
//console.log('Cards before navigating:', cards);
} }
}; };
...@@ -71,6 +74,7 @@ export default function ContentGenerationScreen({ navigation }) { ...@@ -71,6 +74,7 @@ export default function ContentGenerationScreen({ navigation }) {
await soundRef.current.unloadAsync(); await soundRef.current.unloadAsync();
await soundRef.current.loadAsync({ uri: cards[activeIndex].audio }); await soundRef.current.loadAsync({ uri: cards[activeIndex].audio });
await soundRef.current.playAsync(); await soundRef.current.playAsync();
//console.log('Cards before navigating:', cards);
}; };
return ( return (
...@@ -108,7 +112,7 @@ export default function ContentGenerationScreen({ navigation }) { ...@@ -108,7 +112,7 @@ export default function ContentGenerationScreen({ navigation }) {
{index === cards.length - 1 && ( {index === cards.length - 1 && (
<TouchableOpacity <TouchableOpacity
onPress={() => navigation.navigate('FlipCardGame')} onPress={() => navigation.navigate('FlipCardGame', cards )}
style={styles.nextButton} style={styles.nextButton}
> >
<MaterialIcons name="keyboard-arrow-right" size={65} color="#FFCE6D" /> <MaterialIcons name="keyboard-arrow-right" size={65} color="#FFCE6D" />
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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