Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,9 @@ import streamlit as st
|
|
| 2 |
from g4f.client import Client
|
| 3 |
import sqlite3
|
| 4 |
import google.generativeai as genai
|
|
|
|
|
|
|
|
|
|
| 5 |
# import pyttsx3
|
| 6 |
# import pyperclip
|
| 7 |
|
|
@@ -22,6 +25,24 @@ try:
|
|
| 22 |
conn.commit()
|
| 23 |
except Exception as e:
|
| 24 |
st.error(f"An error occurred: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# Streamlit app
|
| 27 |
def main():
|
|
@@ -35,7 +56,8 @@ def main():
|
|
| 35 |
models = {
|
| 36 |
"🚀 Airoboros 70B": "airoboros-70b",
|
| 37 |
"🔮 Gemini Pro": "gemini-pro",
|
| 38 |
-
"
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
columns = st.columns(3) # Split the layout into three columns
|
|
@@ -105,8 +127,14 @@ def main():
|
|
| 105 |
|
| 106 |
except Exception as e:
|
| 107 |
st.error(f"An error occurred: {e}")
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
else:
|
| 111 |
try:
|
| 112 |
client = Client()
|
|
|
|
| 2 |
from g4f.client import Client
|
| 3 |
import sqlite3
|
| 4 |
import google.generativeai as genai
|
| 5 |
+
from diffusers import DiffusionPipeline
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
+
import torch
|
| 8 |
# import pyttsx3
|
| 9 |
# import pyperclip
|
| 10 |
|
|
|
|
| 25 |
conn.commit()
|
| 26 |
except Exception as e:
|
| 27 |
st.error(f"An error occurred: {e}")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def generate_image(pipe, prompt, params):
|
| 31 |
+
img = pipe(prompt, **params).images
|
| 32 |
+
|
| 33 |
+
num_images = len(img)
|
| 34 |
+
if num_images>1:
|
| 35 |
+
fig, ax = plt.subplots(nrows=1, ncols=num_images)
|
| 36 |
+
for i in range(num_images):
|
| 37 |
+
ax[i].imshow(img[i]);
|
| 38 |
+
ax[i].axis('off');
|
| 39 |
+
|
| 40 |
+
else:
|
| 41 |
+
fig = plt.figure()
|
| 42 |
+
plt.imshow(img[0]);
|
| 43 |
+
plt.axis('off');
|
| 44 |
+
plt.tight_layout()
|
| 45 |
+
|
| 46 |
|
| 47 |
# Streamlit app
|
| 48 |
def main():
|
|
|
|
| 56 |
models = {
|
| 57 |
"🚀 Airoboros 70B": "airoboros-70b",
|
| 58 |
"🔮 Gemini Pro": "gemini-pro",
|
| 59 |
+
"📷 StabilityAI": "stabilityai/stable-diffusion-xl-base-1.0"
|
| 60 |
+
|
| 61 |
}
|
| 62 |
|
| 63 |
columns = st.columns(3) # Split the layout into three columns
|
|
|
|
| 127 |
|
| 128 |
except Exception as e:
|
| 129 |
st.error(f"An error occurred: {e}")
|
| 130 |
+
|
| 131 |
+
elif selected_model == "stabilityai/stable-diffusion-xl-base-1.0" or user_input == '/image:':
|
| 132 |
+
pipe = DiffusionPipeline.from_pretrained(models, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
| 133 |
+
pipe.to("cuda")
|
| 134 |
+
|
| 135 |
+
params = {'num_inference_steps': 100, 'num_images_per_prompt': 2}
|
| 136 |
+
generate_image(pipe, prompt, params)
|
| 137 |
+
|
| 138 |
else:
|
| 139 |
try:
|
| 140 |
client = Client()
|