tungdop2 commited on
Commit
bfedca6
·
1 Parent(s): 284cb2b
Files changed (3) hide show
  1. app.py +6 -0
  2. index.html +68 -15
  3. start_vllm.sh +1 -1
app.py CHANGED
@@ -1,4 +1,5 @@
1
  from fastapi import FastAPI
 
2
  from pydantic import BaseModel, Extra
3
  import argparse
4
  from typing import Optional
@@ -32,6 +33,7 @@ class ChallengeImage:
32
  self.challenge_prompt = ChallengePromptGenerator()
33
  self.app = FastAPI(title="Challenge Prompt")
34
  self.app.add_api_route("/", self.__call__, methods=["POST"])
 
35
 
36
  async def __call__(
37
  self,
@@ -46,6 +48,10 @@ class ChallengeImage:
46
  )[0].strip()
47
  return complete_prompt
48
 
 
 
 
 
49
 
50
  if __name__ == "__main__":
51
  args = get_args()
 
1
  from fastapi import FastAPI
2
+ from fastapi.responses import HTMLResponse
3
  from pydantic import BaseModel, Extra
4
  import argparse
5
  from typing import Optional
 
33
  self.challenge_prompt = ChallengePromptGenerator()
34
  self.app = FastAPI(title="Challenge Prompt")
35
  self.app.add_api_route("/", self.__call__, methods=["POST"])
36
+ self.app.add_api_route("/", self.serve_index, methods=["GET"])
37
 
38
  async def __call__(
39
  self,
 
48
  )[0].strip()
49
  return complete_prompt
50
 
51
+ async def serve_index(self):
52
+ with open("index.html", "r") as file:
53
+ return HTMLResponse(content=file.read(), status_code=200)
54
+
55
 
56
  if __name__ == "__main__":
57
  args = get_args()
index.html CHANGED
@@ -1,15 +1,68 @@
1
- <main>
2
- <section id="T2I Prompt Generatpr">
3
- <h2>Text generation using Flan T5</h2>
4
- <form class="text-gen-form">
5
- <label for="text-gen-input">Text prompt</label>
6
- <input
7
- id="text-gen-input"
8
- type="text"
9
- value="German: There are many ducks"
10
- />
11
- <button id="text-gen-submit">Submit</button>
12
- <p class="text-gen-output"></p>
13
- </form>
14
- </section>
15
- </main>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>T2I Prompt Generator</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ margin: 20px;
11
+ }
12
+ label {
13
+ display: block;
14
+ margin: 10px 0 5px;
15
+ }
16
+ input, textarea, button {
17
+ width: 100%;
18
+ padding: 10px;
19
+ margin-bottom: 10px;
20
+ }
21
+ button {
22
+ cursor: pointer;
23
+ }
24
+ #result {
25
+ margin-top: 20px;
26
+ }
27
+ </style>
28
+ </head>
29
+ <body>
30
+ <h1>Challenge Prompt Generator</h1>
31
+ <form id="prompt-form">
32
+ <label for="prompt">Prompt:</label>
33
+ <input type="text" id="prompt" name="prompt" required>
34
+
35
+ <label for="max_length">Max Length (optional):</label>
36
+ <input type="number" id="max_length" name="max_length" value="77">
37
+
38
+ <button type="submit">Generate Prompt</button>
39
+ </form>
40
+ <div id="result">
41
+ <h2>Generated Prompt</h2>
42
+ <p id="generated-prompt"></p>
43
+ </div>
44
+
45
+ <script>
46
+ document.getElementById('prompt-form').addEventListener('submit', async (event) => {
47
+ event.preventDefault();
48
+
49
+ const prompt = document.getElementById('prompt').value;
50
+ const max_length = document.getElementById('max_length').value;
51
+
52
+ const response = await fetch('/', {
53
+ method: 'POST',
54
+ headers: {
55
+ 'Content-Type': 'application/json'
56
+ },
57
+ body: JSON.stringify({
58
+ prompt: prompt,
59
+ max_length: max_length ? parseInt(max_length) : 77
60
+ })
61
+ });
62
+
63
+ const data = await response.json();
64
+ document.getElementById('generated-prompt').innerText = data;
65
+ });
66
+ </script>
67
+ </body>
68
+ </html>
start_vllm.sh CHANGED
@@ -1 +1 @@
1
- python app.py --port 8000
 
1
+ python3 app.py --port 8000