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

word generation save mongo

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