Update app.py
Browse files
app.py
CHANGED
@@ -14,14 +14,15 @@ if not GROQ_API_KEY:
|
|
14 |
# Initialize Groq client
|
15 |
client = Groq(api_key=GROQ_API_KEY)
|
16 |
|
17 |
-
# Set up device and load
|
18 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
19 |
pipe = StableDiffusionPipeline.from_pretrained(
|
20 |
-
|
21 |
-
torch_dtype=torch.float16,
|
22 |
-
safety_checker=None, # Optional:
|
23 |
).to(device)
|
24 |
-
pipe.enable_model_cpu_offload() # Optimize memory
|
25 |
|
26 |
# Function to generate tutor output (lesson, question, feedback)
|
27 |
def generate_tutor_output(subject, difficulty, student_input):
|
@@ -50,7 +51,7 @@ def generate_tutor_output(subject, difficulty, student_input):
|
|
50 |
)
|
51 |
return completion.choices[0].message.content
|
52 |
|
53 |
-
# Function to generate images using
|
54 |
def generate_images(text, selected_model):
|
55 |
if selected_model == "Stable Diffusion (Realism)":
|
56 |
prompt_prefix = "realistic, detailed, vivid colors, "
|
@@ -62,7 +63,7 @@ def generate_images(text, selected_model):
|
|
62 |
results = []
|
63 |
for i in range(3):
|
64 |
modified_text = f"{prompt_prefix}{text} variation {i+1}, high quality"
|
65 |
-
image = pipe(modified_text, num_inference_steps=25).images[0]
|
66 |
results.append(image)
|
67 |
return results
|
68 |
|
@@ -110,11 +111,11 @@ with gr.Blocks(title="AI Tutor with Visuals") as demo:
|
|
110 |
|
111 |
gr.Markdown("""
|
112 |
### How to Use
|
113 |
-
1. **Text Section**: Select a subject and difficulty, type your query, and click 'Generate Lesson & Question'
|
114 |
-
2. **Visual Section**: Select
|
115 |
-
3. Review the AI-generated content
|
116 |
|
117 |
-
*
|
118 |
""")
|
119 |
|
120 |
def process_output_text(subject, difficulty, student_input):
|
|
|
14 |
# Initialize Groq client
|
15 |
client = Groq(api_key=GROQ_API_KEY)
|
16 |
|
17 |
+
# Set up device and load the exact model you specified
|
18 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
19 |
+
model_id = "sd-legacy/stable-diffusion-v1-5" # Your exact model ID
|
20 |
pipe = StableDiffusionPipeline.from_pretrained(
|
21 |
+
model_id,
|
22 |
+
torch_dtype=torch.float16, # Matches your snippet
|
23 |
+
safety_checker=None, # Optional: disabled for flexibility
|
24 |
).to(device)
|
25 |
+
pipe.enable_model_cpu_offload() # Optimize memory for Spaces
|
26 |
|
27 |
# Function to generate tutor output (lesson, question, feedback)
|
28 |
def generate_tutor_output(subject, difficulty, student_input):
|
|
|
51 |
)
|
52 |
return completion.choices[0].message.content
|
53 |
|
54 |
+
# Function to generate images using your model ID
|
55 |
def generate_images(text, selected_model):
|
56 |
if selected_model == "Stable Diffusion (Realism)":
|
57 |
prompt_prefix = "realistic, detailed, vivid colors, "
|
|
|
63 |
results = []
|
64 |
for i in range(3):
|
65 |
modified_text = f"{prompt_prefix}{text} variation {i+1}, high quality"
|
66 |
+
image = pipe(modified_text, num_inference_steps=25).images[0] # Using your model
|
67 |
results.append(image)
|
68 |
return results
|
69 |
|
|
|
111 |
|
112 |
gr.Markdown("""
|
113 |
### How to Use
|
114 |
+
1. **Text Section**: Select a subject and difficulty, type your query, and click 'Generate Lesson & Question'.
|
115 |
+
2. **Visual Section**: Select a style and click 'Generate Visuals' to see 3 images from sd-legacy/stable-diffusion-v1-5.
|
116 |
+
3. Review the AI-generated content!
|
117 |
|
118 |
+
*Example*: Try "a photo of an astronaut riding a horse on mars" for visuals.
|
119 |
""")
|
120 |
|
121 |
def process_output_text(subject, difficulty, student_input):
|