nishant17j03 commited on
Commit
13ba664
1 Parent(s): 7dc6515

Upload 17 files

Browse files
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ static/css/Superalignment-human.png filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request
2
+ from transformers import pipeline
3
+ import logging
4
+
5
+ logging.basicConfig(level=logging.DEBUG)
6
+
7
+ app = Flask(__name__, static_folder='static')
8
+
9
+ def generate_gpt3_text(text):
10
+ generator = pipeline(task='text-generation', model='EleutherAI/gpt-neo-2.7B')
11
+ generated_text = generator(text, max_length=200, num_return_sequences=1, truncation=True)
12
+ return generated_text[0]['generated_text']
13
+
14
+ def generate_gpt2_text(prompt, max_length):
15
+ generator = pipeline('text-generation', model='gpt2')
16
+ generated_text = generator(prompt, max_length=max_length, num_return_sequences=1, truncation=True)
17
+ return generated_text[0]['generated_text']
18
+
19
+ def translate_text_t5(prompt):
20
+ translator = pipeline('translation_en_to_fr', model='t5-small')
21
+ translated_text = translator(prompt, max_length=100)[0]['translation_text']
22
+ return translated_text
23
+
24
+ def translate_text_english_to_hindi(prompt):
25
+ translator = pipeline('translation_en_to_hi', model='Helsinki-NLP/opus-mt-en-hi')
26
+ translated_text = translator(prompt, max_length=100)[0]['translation_text']
27
+ logging.debug(f'Generated text from GPT-3: {translated_text}')
28
+ print('Translated Text (English to French):', translated_text)
29
+ return translated_text
30
+
31
+ def translate_text_hindi_to_english(prompt):
32
+ translator = pipeline('translation_hi_to_en', model='Helsinki-NLP/opus-mt-hi-en')
33
+ translated_text = translator(prompt, max_length=100)[0]['translation_text']
34
+ return translated_text
35
+
36
+ def translate_text_spanish_to_english(prompt):
37
+ translator = pipeline('translation_es_to_en', model='Helsinki-NLP/opus-mt-es-en')
38
+ translated_text = translator(prompt, max_length=100)[0]['translation_text']
39
+ return translated_text
40
+
41
+ def translate_text_german_to_english(prompt):
42
+ translator = pipeline('translation_de_to_en', model='Helsinki-NLP/opus-mt-de-en')
43
+ translated_text = translator(prompt, max_length=100)[0]['translation_text']
44
+ return translated_text
45
+
46
+ def translate_text_french_to_english(prompt):
47
+ translator = pipeline('translation_fr_to_en', model='Helsinki-NLP/opus-mt-fr-en')
48
+ translated_text = translator(prompt, max_length=100)[0]['translation_text']
49
+ return translated_text
50
+
51
+ def translate_text_chinese_to_english(prompt):
52
+ translator = pipeline('translation_zh_to_en', model='Helsinki-NLP/opus-mt-zh-en')
53
+ translated_text = translator(prompt, max_length=100)[0]['translation_text']
54
+ return translated_text
55
+
56
+ def generate_long_content(input_text):
57
+ summarizer = pipeline('summarization', model='t5-small')
58
+ input_format = "summarize: {}".format(input_text)
59
+ generated_summary = summarizer(input_format, max_length=210, num_return_sequences=1, truncation=True)
60
+ output_summary = generated_summary[0]['summary_text']
61
+ return output_summary
62
+
63
+ def generate_text_bert(prompt):
64
+ generator = pipeline('fill-mask', model='bert-base-uncased')
65
+ generated_text = generator(prompt)
66
+ generated_sequences = [result['sequence'] for result in generated_text]
67
+ return generated_sequences
68
+
69
+ @app.route('/', methods=['GET', 'POST'])
70
+ def home():
71
+ generated_text = ''
72
+ if request.method == 'POST':
73
+ try:
74
+ prompt = request.form['prompt']
75
+ model_type = request.form['model_type']
76
+
77
+ logging.debug(f'Prompt received: {prompt}')
78
+ logging.debug(f'Model type selected: {model_type}')
79
+
80
+ if model_type == 'gpt3':
81
+ generated_text = generate_gpt3_text(prompt)
82
+ logging.debug(f'Generated text from GPT-3: {generated_text}')
83
+ elif model_type == 'gpt2':
84
+ max_length = int(request.form['max_length'])
85
+ generated_text = generate_gpt2_text(prompt, max_length)
86
+ logging.debug(f'Generated text from GPT-2: {generated_text}')
87
+ elif model_type == 'translation_en_to_fr':
88
+ max_length = int(request.form['max_length'])
89
+ generated_text = translate_text_t5(prompt)
90
+ logging.debug(f'Generated text from GPT-2: {generated_text}')
91
+ elif model_type == 'translation_en_to_hi':
92
+ generated_text = translate_text_english_to_hindi(prompt)
93
+ logging.debug(f'Generated text from GPT-2: {generated_text}')
94
+ elif model_type == 'translation_hi_to_en':
95
+ generated_text = translate_text_hindi_to_english(prompt)
96
+ logging.debug(f'Generated text from GPT-2: {generated_text}')
97
+ elif model_type == 'translation_es_to_en':
98
+ generated_text = translate_text_spanish_to_english(prompt)
99
+ logging.debug(f'Generated text from GPT-2: {generated_text}')
100
+ elif model_type == 'translation_de_to_en':
101
+ generated_text = translate_text_german_to_english(prompt)
102
+ logging.debug(f'Generated text from GPT-2: {generated_text}')
103
+ elif model_type == 'translation_fr_to_en':
104
+ generated_text = translate_text_french_to_english(prompt)
105
+ logging.debug(f'Generated text from GPT-2: {generated_text}')
106
+ elif model_type == 'translation_zh_to_en':
107
+ generated_text = translate_text_chinese_to_english(prompt)
108
+ logging.debug(f'Generated text from GPT-2: {generated_text}')
109
+ elif model_type == 'summarization':
110
+ generated_text = generate_long_content(prompt)
111
+ logging.debug(f'Generated text from T5: {generated_text}')
112
+ elif model_type == 'Text_bert':
113
+ generated_text = generate_text_bert(prompt)
114
+ logging.debug(f'Generated text from BERT: {generated_text}')
115
+
116
+ except Exception as e:
117
+ logging.error(f'An error occurred: {str(e)}')
118
+
119
+ return render_template('index.html', prompt=prompt, generated_text=generated_text)
120
+
121
+ return render_template('index.html', generated_text=generated_text)
122
+
123
+ if __name__ == '__main__':
124
+ app.run(debug=True)
requirements.txt ADDED
@@ -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/Superalignment-human.png ADDED

Git LFS Details

  • SHA256: 851c881739b04e18f4d0dfcc242256d014d8f236ce6b67af111c913cc2361c30
  • Pointer size: 132 Bytes
  • Size of remote file: 2.43 MB
static/css/image1.jpg ADDED
static/css/image2.jpg ADDED
static/css/image3.jpg ADDED
static/css/image4.jpg ADDED
static/css/image5.jpg ADDED
static/css/img/Kaggle_logo.png ADDED
static/css/img/fb.png ADDED
static/css/img/github.png ADDED
static/css/img/instagram.jpg ADDED
static/css/img/linkdin.png ADDED
static/css/img/signature.png ADDED
static/css/styles.css ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
16
+ body {
17
+ background-image: url('./image5.jpg');
18
+ background-size: cover;
19
+ background-position: center;
20
+ background-color: #f2f2f2;
21
+ display: flex;
22
+ justify-content: center;
23
+ align-items: center;
24
+ height: 100vh;
25
+ margin: 0;
26
+ padding: 0;
27
+ }
28
+
29
+ h1 {
30
+ color: #0607f3;
31
+ text-align: center;
32
+ }
33
+
34
+ form {
35
+ margin-bottom: 20px;
36
+ }
37
+
38
+ label {
39
+ font-weight: bold;
40
+ }
41
+
42
+ input[type="text"] {
43
+ width: 100%;
44
+ padding: 10px;
45
+ margin-top: 5px;
46
+ margin-bottom: 10px;
47
+ border-radius: 3px;
48
+ border: 1px solid #ccc;
49
+ }
50
+
51
+ button {
52
+ padding: 10px 20px;
53
+ background-color: #16cf19;
54
+ color: #fff;
55
+ border: none;
56
+ border-radius: 3px;
57
+ cursor: pointer;
58
+ }
59
+
60
+ button:hover {
61
+ background-color: #0056b3;
62
+ }
63
+
64
+ .social-links {
65
+ display: flex;
66
+ justify-content: center;
67
+ margin-top: 20px;
68
+ background-color: #181818; /* White background for social links */
69
+ padding: 10px;
70
+ border-radius: 8px;
71
+ }
72
+
73
+ .social-links a {
74
+ margin: 0 10px;
75
+ text-decoration: none;
76
+ display: inline-block;
77
+ transition: transform 0.3s ease-in-out;
78
+ }
79
+
80
+ .social-links a img {
81
+ width: 30px; /* Adjust the size of the social link logos */
82
+ height: 30px; /* Adjust the size of the social link logos */
83
+ }
84
+
85
+ .social-links a:hover {
86
+ transform: scale(1.2);
87
+ }
88
+
89
+ .generated-text-container {
90
+ margin-top: 20px;
91
+ border-top: 1px solid #ccc;
92
+ padding-top: 20px;
93
+ background-color: #f9f9f9; /* Background color for generated text */
94
+ border-radius: 3px;
95
+ padding: 10px;
96
+ }
97
+
98
+ h2 {
99
+ margin-bottom: 10px;
100
+ color: #333;
101
+ }
102
+
103
+ p {
104
+ white-space: pre-wrap;
105
+ font-family: 'Courier New', monospace; /* Font style for generated text */
106
+ }
static/images/img.jpg ADDED
templates/index.html ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>NLP Tools</title>
7
+ <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/styles.css') }}">
8
+ </head>
9
+ <body style="background-color: #6ea6ec; font-family: 'Segoe UI', sans-serif; text-align: center;">
10
+
11
+ <div class="background">
12
+ <div class="container" style="max-width: 897px; margin: 50px auto; padding: 20px; background-color: rgba(0, 0, 0, 0.7); color: #ffffff;border-radius: 5px; box-shadow: 0 0 10px rgba(245, 244, 244, 0.1);">
13
+ <h1 style="color: #ffffff; margin-bottom: 20px;">NLP Tools (Open AI) & (Google BERT)</h1>
14
+ <p style="font-size: 16px; margin-bottom: 20px;">Welcome to the NLP Tools project! Select the tool you want to use, enter your prompt or text, and click the button to get results. </p>
15
+
16
+ <form method="POST" action="/" style="margin-bottom: 20px;">
17
+ <label for="prompt" style="font-weight: bold; color: #ffffff;">Enter your prompt or text:</label><br>
18
+ <input type="text" id="prompt" name="prompt" placeholder="Enter Your Text" style="width: 87%; padding: 51px; margin-top: 5px; margin-bottom: 10px; border-radius: 3px; border: 1px solid #ccc; color: #0d0c0c;">
19
+ <br>
20
+ <label for="model_type" style="font-weight: bold; color: #ffffff;">Select Model or Tool Type:</label><br>
21
+ <select id="model_type" name="model_type" required style="width: 100%; padding: 10px; margin-top: 5px; margin-bottom: 10px; border-radius: 3px; border: 1px solid #ccc; color: #090909;">
22
+ <option value="summarization">Summarization</option>
23
+ <option value="gpt2">GPT-2 Text Generation</option>
24
+ <option value="gpt3">GPT-3 Text Generation</option>
25
+ <option value="Text_bert">Generate Mask Text (BERT)</option>
26
+ <option value="translation_en_to_fr">Translation: English to French</option>
27
+ <option value="translation_en_to_hi">Translation: English to Hindi</option>
28
+ <option value="translation_hi_to_en">Translation: Hindi to English</option>
29
+ <option value="translation_es_to_en">Translation: Spanish to English</option>
30
+ <option value="translation_de_to_en">Translation: German to English</option>
31
+ <option value="translation_fr_to_en">Translation: French to English</option>
32
+ <option value="translation_zh_to_en">Translation: Chinese to English</option>
33
+
34
+ </select>
35
+ <br>
36
+ <label for="max_length" style="font-weight: bold; color: #ffffff;">Maximum Length (for Text Generation or Summarization):</label><br>
37
+ <input type="number" id="max_length" name="max_length" min="1" max="1000" value="200" required style="width: 97%; padding: 10px; margin-top: 5px; margin-bottom: 10px; border-radius: 3px; border: 1px solid #ccc; color: #111111;">
38
+ <br>
39
+ <button type="submit" style="padding: 10px 20px; background-color: #302ebd; color: #ffffff; border: none; border-radius: 3px; cursor: pointer; transition: background-color 0.3s;">Generate Text</button>
40
+ </form>
41
+ {% if prompt %}
42
+ <div class="generated-text" style="margin-top: 20px; border-top: 1px solid #ccc; padding-top: 20px; text-align: left;">
43
+ <h2 style="color: #ffffff; margin-bottom: 10px;">Generated Text:</h2>
44
+ <p class="generated_text" style="white-space: pre-wrap; font-size: 16px; line-height: 1.6;">{{ generated_text }}</p>
45
+ </div>
46
+ {% endif %}
47
+ <div class="social-links">
48
+ <a href="https://www.instagram.com/end_of_night.17j03/" target="_blank">
49
+ <img src="../static/css/img/instagram.jpg" alt="Instagram">
50
+ </a>
51
+ <a href="https://www.facebook.com/nishantraghuwanshi.singh.5" target="_blank">
52
+ <img src="../static/css/img/fb.png" alt="Facebook">
53
+ </a>
54
+ <a href="https://www.linkedin.com/in/nishant-raghuwanshi-1509a724a/" target="_blank">
55
+ <img src="../static/css/img/linkdin.png" alt="LinkedIn">
56
+ </a>
57
+ <a href="https://github.com/Nishant2018" target="_blank">
58
+ <img src="../static/css/img/github.png" alt="GitHub">
59
+ </a>
60
+ <a href="https://www.kaggle.com/endofnight17j03" target="_blank">
61
+ <img src="../static/css/img/Kaggle_logo.png" alt="Kaggle">
62
+ </a>
63
+ </div>
64
+ <div class="footer">
65
+ <p>&copy; 2024 Your Website. All rights reserved. | <a href="/terms" style="color: #ffffff;">Terms of Use</a> | <a href="/privacy" style="color: #ffffff;">Privacy Policy</a></p>
66
+ <div class="contact-section" style="margin-top: 30px;">
67
+ <h3 style="color: #ffffff; margin-bottom: 10px;">Contact Us</h3>
68
+ <p style="font-size: 14px; line-height: 1.5; color: #ffffff;">For inquiries or feedback, please contact our team at <a href="mailto:nishantraghuwanshi2018@gmail.com" style="color: #ffffff; text-decoration: underline;">nishantraghuwanshi2018@gmail.com</a>.</p>
69
+
70
+ </div>
71
+
72
+ </div>
73
+ <div class="additional-info" style="margin-top: 30px;">
74
+ <h3 style="color: #ffffff; margin-bottom: 10px;">Additional Information</h3>
75
+ <p style="font-size: 14px; line-height: 1.5;">Explore our NLP Tools project to generate and analyze text using state-of-the-art models. Choose from text generation, translation, or summarization tools to experience the power of natural language processing.</p>
76
+ </div>
77
+ </div>
78
+ </div>
79
+ </body>
80
+ </html>