Skip to content

Commit f055166

Browse files
authored
Add files via upload
1 parent 425a6b6 commit f055166

11 files changed

+173
-0
lines changed

app.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from flask import Flask, render_template, request
2+
from transformers import GPT2LMHeadModel, GPT2Tokenizer, pipeline
3+
4+
app = Flask(__name__, static_folder='static')
5+
6+
def generate_text(prompt, max_length):
7+
generator = pipeline('text-generation', model='gpt2')
8+
generated_text = generator(prompt, max_length=max_length, num_return_sequences=1, truncation=True)
9+
return generated_text[0]['generated_text']
10+
11+
@app.route('/', methods=['GET', 'POST'])
12+
def home():
13+
if request.method == 'POST':
14+
prompt = request.form['prompt']
15+
max_length = int(request.form['max_length'])
16+
generated_text = generate_text(prompt, max_length)
17+
return render_template('index.html', prompt=prompt, generated_text=generated_text)
18+
return render_template('index.html')
19+
20+
if __name__ == '__main__':
21+
app.run(debug=True)

requirements.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Flask==2.0.2
2+
transformers==4.12.0
3+
torch==1.10.0
4+
tensorflow==2.7.0
5+
numpy==1.21.5
6+
pandas==1.3.5

static/css/img/Kaggle_logo.png

12.1 KB
Loading

static/css/img/fb.png

6.18 KB
Loading

static/css/img/github.png

7.08 KB
Loading

static/css/img/instagram.jpg

49.2 KB
Loading

static/css/img/linkdin.png

14.8 KB
Loading

static/css/img/signature.png

7.61 KB
Loading

static/css/styles.css

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
body {
2+
font-family: Arial, sans-serif;
3+
background-color: #5f93ee;
4+
}
5+
6+
.container {
7+
max-width: 800px;
8+
margin: 50px auto;
9+
padding: 20px;
10+
background-color: #fff;
11+
border-radius: 5px;
12+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
13+
}
14+
15+
h1 {
16+
color: #0607f3;
17+
text-align: center;
18+
}
19+
20+
form {
21+
margin-bottom: 20px;
22+
}
23+
24+
label {
25+
font-weight: bold;
26+
}
27+
28+
input[type="text"] {
29+
width: 100%;
30+
padding: 10px;
31+
margin-top: 5px;
32+
margin-bottom: 10px;
33+
border-radius: 3px;
34+
border: 1px solid #ccc;
35+
}
36+
37+
button {
38+
padding: 10px 20px;
39+
background-color: #16cf19;
40+
color: #fff;
41+
border: none;
42+
border-radius: 3px;
43+
cursor: pointer;
44+
}
45+
46+
button:hover {
47+
background-color: #0056b3;
48+
}
49+
50+
.social-links {
51+
display: flex;
52+
justify-content: center;
53+
margin-top: 20px;
54+
background-color: #ffffff; /* White background for social links */
55+
padding: 10px;
56+
border-radius: 8px;
57+
}
58+
59+
.social-links a {
60+
margin: 0 10px;
61+
text-decoration: none;
62+
display: inline-block;
63+
transition: transform 0.3s ease-in-out;
64+
}
65+
66+
.social-links a img {
67+
width: 30px; /* Adjust the size of the social link logos */
68+
height: 30px; /* Adjust the size of the social link logos */
69+
}
70+
71+
.social-links a:hover {
72+
transform: scale(1.2);
73+
}
74+
75+
.generated-text-container {
76+
margin-top: 20px;
77+
border-top: 1px solid #ccc;
78+
padding-top: 20px;
79+
background-color: #f9f9f9; /* Background color for generated text */
80+
border-radius: 3px;
81+
padding: 10px;
82+
}
83+
84+
h2 {
85+
margin-bottom: 10px;
86+
color: #333;
87+
}
88+
89+
p {
90+
white-space: pre-wrap;
91+
font-family: 'Courier New', monospace; /* Font style for generated text */
92+
}

static/images/img.jpg

75.8 KB
Loading

templates/index.html

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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>GPT-2 Text Generation</title>
7+
<link rel="stylesheet" type="text/css" href="../static/css/styles.css">
8+
</head>
9+
<body style="background-color: #6ea6ec; font-family: 'Segoe UI', sans-serif; text-align: center;">
10+
<div class="container" style="max-width: 800px; margin: 50px auto; padding: 20px; background-color: #acb676; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);">
11+
<h1 style="color: #333; margin-bottom: 20px;">GPT-2 Text Generation</h1>
12+
<p style="font-size: 16px; margin-bottom: 20px;">Welcome to the GPT-2 Text Generation project! Enter your prompt and choose the maximum length of the generated text to get started.</p>
13+
<form method="POST" action="/" style="margin-bottom: 20px;">
14+
<label for="prompt" style="font-weight: bold;">Enter your prompt:</label><br>
15+
<input type="text" id="prompt" name="prompt" placeholder="Enter Your Text" style="width: 100%; padding: 10px; margin-top: 5px; margin-bottom: 10px; border-radius: 3px; border: 1px solid hsl(66, 20%, 48%);">
16+
<br>
17+
<label for="max_length" style="font-weight: bold;">Maximum Length:</label><br>
18+
<input type="number" id="max_length" name="max_length" min="1" max="1000" value="200" required style="width: 100%; padding: 10px; margin-top: 5px; margin-bottom: 10px; border-radius: 3px; border: 1px solid #ccc;">
19+
<br>
20+
<button type="submit" style="padding: 10px 20px; background-color: #51ff00; color: #e89898; border: none; border-radius: 3px; cursor: pointer; transition: background-color 0.3s;">Generate Text</button>
21+
</form>
22+
{% if prompt %}
23+
<div class="generated-text" style="margin-top: 20px; border-top: 1px solid #ccc; padding-top: 20px; text-align: left;">
24+
<h2 style="color: #333; margin-bottom: 10px;">Generated Text:</h2>
25+
<p style="white-space: pre-wrap; font-size: 16px; line-height: 1.6;">{{ generated_text }}</p>
26+
</div>
27+
{% endif %}
28+
<div class="social-links">
29+
<a href="https://www.instagram.com/end_of_night.17j03/" target="_blank">
30+
<img src="../static/css/img/instagram.jpg" alt="Instagram">
31+
</a>
32+
<a href="https://www.facebook.com/nishantraghuwanshi.singh.5" target="_blank">
33+
<img src="../static/css/img/fb.png" alt="Facebook">
34+
</a>
35+
<a href="https://www.linkedin.com/in/nishant-raghuwanshi-1509a724a/" target="_blank">
36+
<img src="../static/css/img/linkdin.png" alt="LinkedIn">
37+
</a>
38+
<a href="https://github.com/Nishant2018" target="_blank">
39+
<img src="../static/css/img/github.png" alt="GitHub">
40+
</a>
41+
<a href="https://www.kaggle.com/endofnight17j03" target="_blank">
42+
<img src="../static/css/img/Kaggle_logo.png" alt="Kaggle">
43+
</a>
44+
</div>
45+
<div class="footer">
46+
<p>&copy; 2024 Your Website. All rights reserved. | <a href="/terms">Terms of Use</a> | <a href="/privacy">Privacy Policy</a></p>
47+
</div>
48+
<div class="additional-info" style="margin-top: 30px;">
49+
<h3 style="color: #333; margin-bottom: 10px;">Additional Information</h3>
50+
<p style="font-size: 14px; line-height: 1.5;">Explore our GPT-2 Text Generation project to generate creative and engaging text based on your prompts. This tool uses advanced natural language processing techniques to produce realistic and coherent text outputs.</p>
51+
</div>
52+
</div>
53+
</body>
54+
</html>

0 commit comments

Comments
 (0)