File size: 5,131 Bytes
b89f196 1fc13a0 b89f196 2912bea b89f196 ecd9090 f024495 2eb1363 967efaf 0250d76 b89f196 b0e8d4b b89f196 1fc13a0 b89f196 fac22d0 f2919d0 b89f196 1fc13a0 b0e8d4b 1fc13a0 98adbab 1fc13a0 f1b6599 b0e8d4b 1fc13a0 b89f196 1fc13a0 8a16552 1fc13a0 f1b6599 b0e8d4b f1b6599 b0e8d4b b89f196 f2919d0 cc56cce 22e810f 4f70fb9 2d3723a f2919d0 2558ede 2912bea 2558ede b2e69a4 4e4986b 0c7bb8f 2558ede f29ef8b b2e69a4 64ecb03 dfbec24 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
import os
from googleapiclient.discovery import build
from lang import G4F
from fastapi import FastAPI, Request, Path
from pydantic import BaseModel
from fastapi.middleware.cors import CORSMiddleware
from ImageCreator import generate_image_prodia
app = FastAPI()
app.add_middleware( # add the middleware
CORSMiddleware,
allow_credentials=True, # allow credentials
allow_origins=["*"], # allow all origins
allow_methods=["*"], # allow all methods
allow_headers=["*"], # allow all headers
)
google_api_key = os.environ["GOOGLE_API_KEY"]
cse_id = os.environ["GOOGLE_CSE_ID"]
def search_google(query):
service = build("customsearch", "v1", developerKey=google_api_key)
result = service.cse().list(
q=query,
cx=cse_id
).execute()
return result['items']
@app.get("/")
def hello():
return "Hello! My name is Linlada."
def llm(prompt, model):
llm = G4F(model=model)
response = llm(prompt)
return response
def gpt_with_google_search(prompt, model):
search_results = search_google(prompt)
text = ""
ref = ""
ref_count = 1
for item in search_results:
text += item['title'] + "\n" + item['snippet'] + "\n\n"
ref += " [{}] {} ({})\n".format(ref_count, item['title'], item['link'])
ref_count += 1
results = llm(prompt = f'Summarize: {text}', model = model)
res = "{} \n\n{}".format(results, ref)
return res
class Linlada(BaseModel):
prompt: str
web_access: str = True
model: str = os.environ['default_model']
@app.post('/linlada')
def linlada(request: Linlada):
prompt = request.prompt
model = request.model
web_access = request.web_access
if web_access == "True":
chat = gpt_with_google_search(prompt, model)
else:
chat = llm(prompt, model)
return chat
class User(BaseModel):
prompt: str
model: str = None
sampler: str = None
seed: int = None
neg: str = None
@app.post("/imagen")
def generate_image(request: User):
prompt = request.prompt
model = request.model
sampler = request.sampler
seed = request.seed
neg = request.neg
response = generate_image_prodia(prompt, model, sampler, seed, neg)
return {"image": response}
details = {
1: {'Absolute Reality V1.6': 'absolutereality_V16.safetensors [37db0fc3]',
'Analog V1': 'analog-diffusion-1.0.ckpt [9ca13f02]',
'Anything V3': 'anythingv3_0-pruned.ckpt [2700c435]',
'Anything V4.5': 'anything-v4.5-pruned.ckpt [65745d25]',
'Anything V5': 'anythingV5_PrtRE.safetensors [893e49b9]',
'AbyssOrangeMix V3': 'AOM3A3_orangemixs.safetensors [9600da17]',
'Deliberate V2': 'deliberate_v2.safetensors [10ec4b29]',
'Dreamlike Diffusion V1': 'dreamlike-diffusion-1.0.safetensors [5c9fd6e0]',
'Dreamlike Diffusion V2': 'dreamlike-diffusion-2.0.safetensors [fdcf65e7]',
'Dreamshaper 6 baked vae': 'dreamshaper_6BakedVae.safetensors [114c8abb]',
'Dreamshaper 7': 'dreamshaper_7.safetensors [5cf5ae06]',
'Dreamshaper 8': 'dreamshaper_8.safetensors [9d40847d]',
'Eimis Anime Diffusion V1.0': 'EimisAnimeDiffusion_V1.ckpt [4f828a15]',
"Elldreth's Vivid": 'elldreths-vivid-mix.safetensors [342d9d26]',
'Lyriel V1.6': 'lyriel_v16.safetensors [68fceea2]',
'MechaMix V1.0': 'mechamix_v10.safetensors [ee685731]',
'MeinaMix Meina V9': 'meinamix_meinaV9.safetensors [2ec66ab0]',
'MeinaMix Meina V11': 'meinamix_meinaV11.safetensors [b56ce717]',
'Openjourney V4': 'openjourney_V4.ckpt [ca2f377f]',
'Portrait+ V1': 'portraitplus_V1.0.safetensors [1400e684]',
'Realistic Vision V1.4': 'Realistic_Vision_V1.4-pruned-fp16.safetensors [8d21810b]',
'Realistic Vision V4.0': 'Realistic_Vision_V4.0.safetensors [29a7afaa]',
'Realistic Vision V5.0': 'Realistic_Vision_V5.0.safetensors [614d1063]',
'Redshift Diffusion V1.0': 'redshift_diffusion-V10.safetensors [1400e684]',
'ReV Animated V1.2.2': 'revAnimated_v122.safetensors [3f4fefd9]',
'SD V1.4': 'sdv1_4.ckpt [7460a6fa]',
'SD V1.5': 'v1-5-pruned-emaonly.ckpt [81761151]',
"Shonin's Beautiful People V1.0": 'shoninsBeautiful_v10.safetensors [25d8c546]',
"TheAlly's Mix II": 'theallys-mix-ii-churned.safetensors [5d9225a4]',
'Timeless V1': 'timeless-1.0.ckpt [7c4971d4]'
},
2: {
'Euler': 'Euler',
'Euler a': 'Euler a',
'Heun': 'Heun',
'DPM++ 2M Karras': 'DPM++ 2M Karras',
'DPM++ SDE Karras': 'DPM++ SDE Karras',
'DDIM': 'DDIM'
}
}
@app.get("/imagen-details/{detail_id}")
def image_detail(detail_id: int = Path(None, description="The ID of 1.model id and 2.sampler id", gt=0, lt=3)):
return details[detail_id]
class Test(BaseModel):
prompt: str
model: str = 'gpt-3.5-turbo'
neg: str = True
@app.post("/test")
def test(request: Test):
if neg == True:
chat = "hello world"
elif neg == "True":
chat = "Hi there"
else:
chat = "Hi world"
return chat
|