Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,34 @@
|
|
1 |
-
import os
|
2 |
-
import requests
|
3 |
-
import yaml
|
4 |
from flask import Flask, request, jsonify
|
5 |
-
from dotenv import load_dotenv
|
6 |
-
from PIL import Image
|
7 |
-
import io
|
8 |
from transformers import pipeline
|
9 |
|
10 |
-
# Load environment variables
|
11 |
-
load_dotenv()
|
12 |
-
api_key = os.getenv('HF_API_KEY')
|
13 |
-
model_path = os.getenv('MODEL_PATH')
|
14 |
-
|
15 |
app = Flask(__name__)
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
def
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
result = process_image(image)
|
44 |
-
return jsonify({"result": result})
|
45 |
-
else:
|
46 |
-
return jsonify({"error": "No input provided"})
|
47 |
-
|
48 |
-
@app.route('/', methods=['GET'])
|
49 |
-
def index():
|
50 |
-
return "Welcome to My AI! Use /predict to interact."
|
51 |
|
52 |
if __name__ == '__main__':
|
53 |
-
app.run(debug=True
|
|
|
|
|
|
|
|
|
1 |
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)
|