alaa-ahmed14 commited on
Commit
d1153c0
·
verified ·
1 Parent(s): 18e9486

Create index.html

Browse files
Files changed (1) hide show
  1. index.html +100 -0
index.html ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ <title>STEMerald-2b API</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ margin: 20px;
11
+ padding: 20px;
12
+ background-color: #f5f5f5;
13
+ }
14
+ #container {
15
+ max-width: 600px;
16
+ margin: auto;
17
+ background: white;
18
+ padding: 20px;
19
+ border-radius: 8px;
20
+ box-shadow: 0 0 10px rgba(0,0,0,0.1);
21
+ }
22
+ textarea {
23
+ width: 100%;
24
+ height: 100px;
25
+ margin-bottom: 10px;
26
+ border-radius: 4px;
27
+ border: 1px solid #ccc;
28
+ padding: 10px;
29
+ font-size: 16px;
30
+ }
31
+ button {
32
+ background-color: #4CAF50;
33
+ color: white;
34
+ padding: 10px 20px;
35
+ border: none;
36
+ border-radius: 4px;
37
+ cursor: pointer;
38
+ }
39
+ button:hover {
40
+ background-color: #45a049;
41
+ }
42
+ #output {
43
+ margin-top: 20px;
44
+ padding: 10px;
45
+ border: 1px solid #ccc;
46
+ border-radius: 4px;
47
+ background-color: #e8f4e5;
48
+ }
49
+ </style>
50
+ </head>
51
+ <body>
52
+ <div id="container">
53
+ <h2>STEMerald-2b API</h2>
54
+ <textarea id="question" placeholder="Type your question here..."></textarea>
55
+ <button id="submit-btn">Submit</button>
56
+ <div id="output"></div>
57
+ </div>
58
+ <script>
59
+ document.getElementById('submit-btn').addEventListener('click', async () => {
60
+ const question = document.getElementById('question').value;
61
+ const outputDiv = document.getElementById('output');
62
+
63
+ // Clear previous output
64
+ outputDiv.innerHTML = "";
65
+
66
+ if (question.trim() === "") {
67
+ outputDiv.innerHTML = "Please enter a question.";
68
+ return;
69
+ }
70
+
71
+ try {
72
+ const response = await fetch("http://localhost:7860/generate/", {
73
+ method: "POST",
74
+ headers: {
75
+ "Content-Type": "application/json"
76
+ },
77
+ body: JSON.stringify({ prompt: question })
78
+ });
79
+
80
+ if (!response.ok) {
81
+ throw new Error("Network response was not ok");
82
+ }
83
+
84
+ const data = await response.json();
85
+ outputDiv.innerHTML = "<strong>Response:</strong> " + data.generated_text;
86
+
87
+ } catch (error) {
88
+ outputDiv.innerHTML = "Error: " + error.message;
89
+ }
90
+ });
91
+
92
+ // Allow pressing Enter to submit the question
93
+ document.getElementById('question').addEventListener('keypress', function (e) {
94
+ if (e.key === 'Enter') {
95
+ document.getElementById('submit-btn').click();
96
+ }
97
+ });
98
+ </script>
99
+ </body>
100
+ </html>