2023-01-03 01:57:12 +00:00
|
|
|
<template lang="pug">
|
|
|
|
div
|
|
|
|
.container.mx-auto.p-4
|
|
|
|
form(v-if="!loading", @submit.prevent="submitForm")
|
|
|
|
label.block.font-bold.text-lg.mb-2(for="question") Question
|
|
|
|
textarea#question.border.rounded.w-full.py-2.px-3(
|
|
|
|
v-model="form.question",
|
2023-01-02 16:34:56 +00:00
|
|
|
rows="5"
|
2023-01-03 01:57:12 +00:00
|
|
|
)
|
|
|
|
button.bg-blue-500.text-white.font-bold.py-2.px-4.rounded(
|
|
|
|
class="hover:bg-blue-700",
|
|
|
|
type="submit",
|
|
|
|
v-if="form.submitCounter < 600"
|
|
|
|
)
|
|
|
|
| Submit
|
|
|
|
p.bg-red-500(v-if="form.submitCounter >= 600") Please wait for sometime as you have made 600 requests within one hour.
|
|
|
|
.flex.items-center.justify-center.h-screen(v-if="loading")
|
|
|
|
loadingwheel
|
|
|
|
.mt-4.font-bold(v-if="answer !== null")
|
|
|
|
p Question: {{ tmpquestion }}
|
|
|
|
p.typed-text Answer: {{ typedAnswer }}
|
|
|
|
p Urls:
|
|
|
|
ul(v-if="typedAnswer.length === answer.length && urls !== null")
|
|
|
|
li(v-for="url in urls", :key="url")
|
|
|
|
a.url(:href="url") - {{ url }}
|
|
|
|
|
2023-01-02 16:34:56 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-01-03 01:57:12 +00:00
|
|
|
import LoadingWheel from '~/components/LoadingWheel.vue'
|
|
|
|
|
2023-01-02 16:34:56 +00:00
|
|
|
export default {
|
2023-01-03 01:57:12 +00:00
|
|
|
components: { LoadingWheel },
|
2023-01-02 16:34:56 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
form: {
|
2023-01-03 01:57:12 +00:00
|
|
|
question: '',
|
|
|
|
submitCounter: 0
|
2023-01-02 16:34:56 +00:00
|
|
|
},
|
|
|
|
answer: null,
|
|
|
|
loading: false,
|
|
|
|
typedAnswer: '',
|
|
|
|
urls: null
|
|
|
|
}
|
|
|
|
},
|
2023-01-03 01:57:12 +00:00
|
|
|
created() {
|
|
|
|
setInterval(() => {
|
|
|
|
this.form.submitCounter = 0
|
|
|
|
}, 3600000)
|
|
|
|
},
|
2023-01-02 16:34:56 +00:00
|
|
|
methods: {
|
|
|
|
resetForm() {
|
|
|
|
this.form.question = ''
|
|
|
|
this.answer = null
|
|
|
|
this.loading = false
|
|
|
|
this.typedAnswer = ''
|
|
|
|
this.urls = null
|
|
|
|
},
|
|
|
|
async submitForm() {
|
2023-01-03 01:57:12 +00:00
|
|
|
this.form.submitCounter++
|
2023-01-02 16:34:56 +00:00
|
|
|
this.loading = true
|
|
|
|
try {
|
|
|
|
const { data } = await this.$axios.post(
|
|
|
|
'http://localhost:8080/api/nlp/no-context/question-answering/',
|
|
|
|
{
|
|
|
|
question: this.form.question
|
|
|
|
}
|
|
|
|
)
|
|
|
|
this.tmpquestion = this.form.question
|
|
|
|
this.resetForm()
|
|
|
|
this.answer = data.response.answer
|
2023-01-03 01:57:12 +00:00
|
|
|
const typingInterval = setInterval(() => {
|
2023-01-02 16:34:56 +00:00
|
|
|
this.typedAnswer +=
|
|
|
|
this.answer[this.typedAnswer.length] || ''
|
|
|
|
if (this.typedAnswer.length === this.answer.length) {
|
2023-01-03 01:57:12 +00:00
|
|
|
clearInterval(typingInterval)
|
2023-01-02 16:34:56 +00:00
|
|
|
}
|
|
|
|
}, 150)
|
|
|
|
this.urls = data.resources
|
|
|
|
} catch (error) {
|
|
|
|
// console.error(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2023-01-03 01:57:12 +00:00
|
|
|
<style lang="scss">
|
2023-01-02 16:34:56 +00:00
|
|
|
.typed-text {
|
|
|
|
position: relative;
|
|
|
|
display: inline;
|
|
|
|
}
|
|
|
|
|
|
|
|
.typed-text::after {
|
|
|
|
content: '|';
|
|
|
|
animation: blink 0.7s infinite;
|
|
|
|
}
|
|
|
|
|
|
|
|
@keyframes blink {
|
|
|
|
0% {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
100% {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|