gautamethiraj commited on
Commit
c856509
·
1 Parent(s): 2cfbbc3

api for basic html

Browse files
Files changed (1) hide show
  1. econ-chat.html +46 -0
econ-chat.html ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <script type="module" src="https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js"></script>
7
+ <title>econ-chat</title>
8
+ </head>
9
+ <body>
10
+ <h1>econ-chat for eLearning</h1>
11
+ <h2>Metropolen</h2>
12
+ <div>
13
+ <form id="question-form">
14
+ <input type="text" id="question" placeholder="e.g. Wer ist Martin Keßler?">
15
+ <input type="submit" value="Answer">
16
+ </form>
17
+ </div>
18
+ <div id="result"></div>
19
+
20
+ <script type="module">
21
+ import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js";
22
+
23
+ const client = await Client.connect("gautamethiraj/econ-chat");
24
+
25
+ document.getElementById('question-form').addEventListener('submit', async function(event) {
26
+ event.preventDefault(); // Prevent the default form submission
27
+
28
+ const questionInput = document.getElementById('question');
29
+ const question = questionInput.value;
30
+
31
+ const resultDiv = document.getElementById('result');
32
+ resultDiv.textContent = 'Loading...'; // Show a loading message
33
+
34
+ try {
35
+ const result = await client.predict("/predict", {
36
+ frage: question,
37
+ });
38
+
39
+ resultDiv.textContent = result.data; // Display the result on the page
40
+ } catch (error) {
41
+ resultDiv.textContent = 'An error occurred. Please try again.'; // Handle errors
42
+ }
43
+ });
44
+ </script>
45
+ </body>
46
+ </html>