Erfan11 commited on
Commit
54004ae
1 Parent(s): 35e951b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -26
app.py CHANGED
@@ -2,33 +2,13 @@ from flask import Flask, request, jsonify
2
  from transformers import pipeline
3
 
4
  app = Flask(__name__)
5
-
6
- # Initialize the text generation pipeline
7
- generator = pipeline('text-generation', model='gpt2') # Replace 'gpt2' with your model
8
-
9
- @app.route('/')
10
- def home():
11
- return '''
12
- <html>
13
- <body>
14
- <h1>Text Generation</h1>
15
- <form action="/generate" method="post">
16
- <textarea name="text_input" rows="4" cols="50" placeholder="Enter text here..."></textarea><br>
17
- <input type="submit" value="Generate">
18
- </form>
19
- </body>
20
- </html>
21
- '''
22
 
23
  @app.route('/generate', methods=['POST'])
24
- def generate():
25
- text_input = request.form['text_input']
26
- if text_input:
27
- # Generate text using the model
28
- result = generator(text_input, max_length=100, num_return_sequences=1)
29
- generated_text = result[0]['generated_text']
30
- return jsonify({'generated_text': generated_text})
31
- return jsonify({'error': 'No input provided'}), 400
32
 
33
  if __name__ == '__main__':
34
- app.run(debug=True)
 
2
  from transformers import pipeline
3
 
4
  app = Flask(__name__)
5
+ model = pipeline('text-generation', model='Erfan11/Neuracraft')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  @app.route('/generate', methods=['POST'])
8
+ def generate_text():
9
+ input_text = request.json.get('input_text', '')
10
+ result = model(input_text, max_length=100)
11
+ return jsonify(result)
 
 
 
 
12
 
13
  if __name__ == '__main__':
14
+ app.run(debug=True, host='0.0.0.0', port=5000)