huynhtrungkiet09032005 commited on
Commit
9ad1f3e
·
verified ·
1 Parent(s): 32cd9ab

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +3 -1
  2. static/index.html +103 -0
app.py CHANGED
@@ -290,4 +290,6 @@ async def generate_creative_poetry(request: PoetryRequest):
290
 
291
  if __name__ == "__main__":
292
  import uvicorn
293
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
 
 
290
 
291
  if __name__ == "__main__":
292
  import uvicorn
293
+ # Use port 7860 for Hugging Face Spaces
294
+ port = int(os.getenv("PORT", 7860))
295
+ uvicorn.run(app, host="0.0.0.0", port=port)
static/index.html ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>AI Poetry Generator</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ max-width: 800px;
11
+ margin: 0 auto;
12
+ padding: 20px;
13
+ background-color: #f5f5f5;
14
+ }
15
+ .container {
16
+ background-color: white;
17
+ padding: 20px;
18
+ border-radius: 8px;
19
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
20
+ }
21
+ textarea {
22
+ width: 100%;
23
+ height: 100px;
24
+ margin: 10px 0;
25
+ padding: 10px;
26
+ border: 1px solid #ddd;
27
+ border-radius: 4px;
28
+ }
29
+ button {
30
+ background-color: #007bff;
31
+ color: white;
32
+ border: none;
33
+ padding: 10px 20px;
34
+ border-radius: 4px;
35
+ cursor: pointer;
36
+ }
37
+ button:hover {
38
+ background-color: #0056b3;
39
+ }
40
+ #result {
41
+ margin-top: 20px;
42
+ white-space: pre-wrap;
43
+ }
44
+ </style>
45
+ </head>
46
+ <body>
47
+ <div class="container">
48
+ <h1>AI Poetry Generator</h1>
49
+ <div>
50
+ <label for="prompt">Enter your prompt:</label>
51
+ <textarea id="prompt" placeholder="Enter a few words to start your poem..."></textarea>
52
+ </div>
53
+ <div>
54
+ <label for="maxLength">Maximum Length:</label>
55
+ <input type="number" id="maxLength" value="300" min="50" max="1000">
56
+ </div>
57
+ <div>
58
+ <label for="temperature">Temperature:</label>
59
+ <input type="range" id="temperature" min="0.1" max="2.0" step="0.1" value="1.0">
60
+ <span id="tempValue">1.0</span>
61
+ </div>
62
+ <button onclick="generatePoetry()">Generate Poetry</button>
63
+ <div id="result"></div>
64
+ </div>
65
+
66
+ <script>
67
+ document.getElementById('temperature').addEventListener('input', function(e) {
68
+ document.getElementById('tempValue').textContent = e.target.value;
69
+ });
70
+
71
+ async function generatePoetry() {
72
+ const prompt = document.getElementById('prompt').value;
73
+ const maxLength = parseInt(document.getElementById('maxLength').value);
74
+ const temperature = parseFloat(document.getElementById('temperature').value);
75
+
76
+ if (!prompt) {
77
+ alert('Please enter a prompt');
78
+ return;
79
+ }
80
+
81
+ try {
82
+ const response = await fetch('/generate_creative', {
83
+ method: 'POST',
84
+ headers: {
85
+ 'Content-Type': 'application/json',
86
+ },
87
+ body: JSON.stringify({
88
+ prompt: prompt,
89
+ max_length: maxLength,
90
+ temperature: temperature
91
+ })
92
+ });
93
+
94
+ const data = await response.json();
95
+ document.getElementById('result').textContent = data.generated_text;
96
+ } catch (error) {
97
+ console.error('Error:', error);
98
+ document.getElementById('result').textContent = 'Error generating poetry. Please try again.';
99
+ }
100
+ }
101
+ </script>
102
+ </body>
103
+ </html>