aus10powell commited on
Commit
25ee46d
1 Parent(s): 62a5163

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +69 -16
templates/index.html CHANGED
@@ -15,6 +15,10 @@
15
  <div class="page">
16
  <h1>Twitter Accounts</h1>
17
  <div class="form">
 
 
 
 
18
  <label for="account">Choose the Twitter account you'd like to generate a response to your input:</label>
19
  <select name="account" id="account">
20
  <option value="alikarimi_ak8">alikarimi_ak8</option>
@@ -31,17 +35,14 @@
31
  <div id="form">
32
  <div class="tweets">
33
  <h2>Tweets (Live)</h2>
34
- <iframe id="tweetsFrame" width="850" height="200" frameborder="0"></iframe>
35
  </div>
36
 
37
  <div id="summary">
38
- <button id="generate-summary">Generate Summary</button>
39
- <textarea id="output-summary" placeholder="Generated text will appear here..."></textarea>
40
- </div>
41
- <div class="inner">
42
- <h2>Twitter Account Info (Live)</h2>
43
- <iframe src="/accounts" width=850 height="200" frameborder="0"></iframe>
44
  </div>
 
45
  </div>
46
  <div id="outer">
47
  <h2>Twitter Account Analysis (Historical)</h2>
@@ -60,19 +61,71 @@
60
 
61
  <script src="../static/main.js"></script>
62
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  window.onload = function () {
64
  generateTweets(); // Call generateTweets() when the page finishes loading
65
-
66
  };
67
- document.getElementById("account").addEventListener("change", function () {
 
68
  generateTweets(); // Call generateTweets() whenever a new account is selected
69
  });
70
- function generateTweets() {
71
- var account = document.getElementById("account").value;
72
- console.log("What up")
73
- var tweetsFrame = document.getElementById("tweetsFrame");
74
- tweetsFrame.src = "/tweets/" + account;
75
- console.log(tweetsFrame.src)
76
 
77
- }</script>
78
  </html>
 
15
  <div class="page">
16
  <h1>Twitter Accounts</h1>
17
  <div class="form">
18
+ <div class="inner">
19
+ <h2>Twitter Account Info (Live)</h2>
20
+ <iframe src="/accounts" width=850 height="250" frameborder="0"></iframe>
21
+ </div>
22
  <label for="account">Choose the Twitter account you'd like to generate a response to your input:</label>
23
  <select name="account" id="account">
24
  <option value="alikarimi_ak8">alikarimi_ak8</option>
 
35
  <div id="form">
36
  <div class="tweets">
37
  <h2>Tweets (Live)</h2>
38
+ <iframe id="tweetsFrame" width="850" height="300" frameborder="0"></iframe>
39
  </div>
40
 
41
  <div id="summary">
42
+ <button id="generateSummary">Generate Summary</button>
43
+ <textarea id="outputSummary" placeholder="Generated text will appear here..." style="width: 100%; height: 150px;"></textarea>
 
 
 
 
44
  </div>
45
+
46
  </div>
47
  <div id="outer">
48
  <h2>Twitter Account Analysis (Historical)</h2>
 
61
 
62
  <script src="../static/main.js"></script>
63
  <script>
64
+ async function fastApiRequest(path, options) {
65
+ try {
66
+ const response = await fetch(path, options);
67
+ const data = await response.json();
68
+ return data;
69
+ } catch (error) {
70
+ console.error(error);
71
+ }
72
+ }
73
+ function generateTweets() {
74
+ var account = document.getElementById("account").value;
75
+ var tweetsFrame = document.getElementById("tweetsFrame");
76
+ var outputSummary = document.getElementById("outputSummary");
77
+ outputSummary.value = 'Tweets being pulled and summarized...';
78
+
79
+ // Create a new text node
80
+ var loadingText = document.createTextNode("Loading...");
81
+
82
+ // Append the text node to the iframe element
83
+ tweetsFrame.appendChild(loadingText);
84
+ // Set the iframe element's visibility to "hidden"
85
+ //tweetsFrame.style.visibility = "hidden";
86
+
87
+
88
+ // Send an AJAX request to the server to retrieve the tweets data
89
+ fastApiRequest('/tweets/' + account)
90
+ .then(response => {
91
+ var tweetsHtml = response.html;
92
+ var tweetsData = response.data;
93
+
94
+
95
+ // Display the HTML version of the tweets
96
+ tweetsFrame.innerHTML = tweetsHtml;
97
+ //tweetsFrame.src = tweetsHtml;//"/tweets/" + account;
98
+ tweetsFrame.srcdoc = tweetsHtml;
99
+ // Log that tweetsFrame is being updated
100
+ console.log('tweetsFrame is being updated. ');
101
+
102
+ // Make a POST request to the /api/generate_summary endpoint
103
+ fastApiRequest('/api/generate_summary', {
104
+ method: 'POST',
105
+ headers: { 'Content-Type': 'application/json' },
106
+ body: JSON.stringify({ tweetsData: tweetsData })
107
+ })
108
+ .then(summaryResponse => {
109
+ console.log('Summary response:', summaryResponse);
110
+ // Process the summary response as needed
111
+ outputSummary.value = summaryResponse.tweets_summary;
112
+ })
113
+ .catch(error => {
114
+ console.error('Failed to generate summary:', error);
115
+ });
116
+ })
117
+ .catch(error => {
118
+ console.error('Failed to retrieve tweets:', error);
119
+ });
120
+ }
121
+
122
  window.onload = function () {
123
  generateTweets(); // Call generateTweets() when the page finishes loading
 
124
  };
125
+
126
+ document.getElementById("account").addEventListener("change", function () {
127
  generateTweets(); // Call generateTweets() whenever a new account is selected
128
  });
129
+ </script>
 
 
 
 
 
130
 
 
131
  </html>