MUST DO
app.py
from flask import Flask,request,render_template
import replicate
import os
import time
os.environ["REPLICATE_API_TOKEN"]="r8_2idkAutIh1jCAVVRIbEDgqt9zNUdbhG2cS1AF"
app = Flask(__name__)
r = ""
first_time = 1
@app.route("/",methods=["GET","POST"])
def index():
return(render_template("index.html"))
@app.route("/main",methods=["GET","POST"])
def main():
global r,first_time
if first_time==1:
r = request.form.get("r")
first_time=0
return(render_template("main.html",r=r))
@app.route("/text_gpt",methods=["GET","POST"])
def text_gpt():
return(render_template("text_gpt.html"))
@app.route("/text_result",methods=["GET","POST"])
def text_result():
q = request.form.get("q")
return(render_template("text_result.html",r="API not ready"))
@app.route("/image_gpt",methods=["GET","POST"])
def image_gpt():
return(render_template("image_gpt.html"))
@app.route("/image_result",methods=["GET","POST"])
def image_result():
q = request.form.get("q")
r = replicate.run(
"stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
input={
"prompt": q,
}
)
time.sleep(10)
return(render_template("image_result.html",r=r[0]))
@app.route("/end",methods=["GET","POST"])
def end():
global first_time,r
first_time = 1
return(render_template("end.html",r=r))
if __name__ == "__main__":
app.run()
==============
index.html
<style>
.container{width:100%;margin:auto}
@media (min-width:600px) {.container{width: 80%;}}
@media (min-width:768px) {.container{width: 60%;}}
@media (min-width:1024px) {.container{width: 50%;}}
</style>
<div class="container">
<h1>Hi, {{r}}. How can help you today?</h1>
<form action="/text_gpt" method="post">
<input type = "submit" value="Text Generator" style="width:200px;height:50px;">
</form>
<form action="/image_gpt" method="post">
<input type = "submit" value="Image Generator" style="width:200px;height:50px;">
</form>
<form action="/end" method="post">
<input type = "submit" value="END" style="width:200px;height:50px;">
</form>
</div>
===================
text_gpt.html
<style>
.container{width:100%;margin:auto}
@media (min-width:600px) {.container{width: 80%;}}
@media (min-width:768px) {.container{width: 60%;}}
@media (min-width:1024px) {.container{width: 50%;}}
</style>
<div class="container">
<h1>Welcome to Text Generator (chatGPT)</h1>
<form action="/text_result" method="post">
<h2>Question </h2>
<input type = "text" name="q" style="width:100px;height:50px">
<p><input type = "submit" value="Enter" style="width:100px;height:50px"></p>
</form>
</div>
====================
text_result.html
<style>
.container{width:100%;margin:auto}
@media (min-width:600px) {.container{width: 80%;}}
@media (min-width:768px) {.container{width: 60%;}}
@media (min-width:1024px) {.container{width: 50%;}}
</style>
<div class="container">
<h1>The text generated by chatGPT : </h1>
<p><h2>{{r}}</h2></p>
<form action="/main" method="post">
<input type = "submit" value="Main" style="width:200px;height:100px;">
</form>
<form action="/end" method="post">
<input type = "submit" value="End" style="width:200px;height:100px;">
</form>
</div>
=================
image_gpt.html
<style>
.container{width:100%;margin:auto}
@media (min-width:600px) {.container{width: 80%;}}
@media (min-width:768px) {.container{width: 60%;}}
@media (min-width:1024px) {.container{width: 50%;}}
</style>
<div class="container">
<h1>Welcome to Image Generator (Midjourney)</h1>
<form action="/image_result" method="post">
<h2>Please describe the picture you want </h2>
<input type = "text" name="q" style="width:100px;height:50px">
<p><input type = "submit" value="Enter" style="width:100px;height:50px"></p>
</form>
</div>
=================
image_result.html
<style>
.container{width:100%;margin:auto}
@media (min-width:600px) {.container{width: 80%;}}
@media (min-width:768px) {.container{width: 60%;}}
@media (min-width:1024px) {.container{width: 50%;}}
</style>
<div class="container">
<h1>The image generated by Midjourney : </h1>
<p><h6>{{r}}</h6></p>
<p><img src={{r}} width="320" height="240"></p>
<form action="/main" method="post">
<input type = "submit" value="Main" style="width:200px;height:100px;">
</form>
<form action="/end" method="post">
<input type = "submit" value="End" style="width:200px;height:100px;">
</form>
</div>
=================
end.html
<style>
.container{width:100%;margin:auto}
@media (min-width:600px) {.container{width: 80%;}}
@media (min-width:768px) {.container{width: 60%;}}
@media (min-width:1024px) {.container{width: 50%;}}
</style>
<div class="container">
<h1>Thank you for visiting us, {{r}}. Good bye!! See you again soon !!</h1>
</div>
gunicorn