Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from groq import Groq
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
def generate_tutor_output(subject, difficulty, student_input):
|
| 9 |
prompt = f"""
|
|
@@ -18,32 +17,25 @@ def generate_tutor_output(subject, difficulty, student_input):
|
|
| 18 |
Format your response as a JSON object with keys: "lesson", "question", "feedback"
|
| 19 |
"""
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
"content": prompt,
|
| 30 |
-
}
|
| 31 |
-
],
|
| 32 |
-
model="mixtral-8x7b-32768", # Model for text generation
|
| 33 |
-
max_tokens=1000,
|
| 34 |
-
)
|
| 35 |
-
|
| 36 |
-
return completion.choices[0].message.content
|
| 37 |
|
| 38 |
-
# Function to generate visual output
|
| 39 |
-
def generate_visual(topic):
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
# For now, returning a placeholder image.
|
| 46 |
-
return "https://via.placeholder.com/500x300.png?text=" + topic.replace(" ", "+")
|
| 47 |
|
| 48 |
# Set up the Gradio interface
|
| 49 |
with gr.Blocks() as demo:
|
|
@@ -78,6 +70,7 @@ with gr.Blocks() as demo:
|
|
| 78 |
# Separate section for visual generation
|
| 79 |
with gr.Row():
|
| 80 |
topic_for_visual = gr.Textbox(label="Topic for Visual", placeholder="Generated Topic")
|
|
|
|
| 81 |
generate_visual_button = gr.Button("Generate Visual Output")
|
| 82 |
visual_output = gr.Image(label="Generated Visual")
|
| 83 |
|
|
@@ -94,12 +87,9 @@ with gr.Blocks() as demo:
|
|
| 94 |
|
| 95 |
# Function to process lesson and pass the topic for visual generation
|
| 96 |
def process_lesson_output(subject, difficulty, student_input):
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
return parsed["lesson"], parsed["question"], parsed["feedback"], student_input
|
| 101 |
-
except Exception as e:
|
| 102 |
-
return f"Error processing output: {e}", "No question available", "No feedback available", ""
|
| 103 |
|
| 104 |
# Generate Lesson Button
|
| 105 |
generate_lesson_button.click(
|
|
@@ -111,7 +101,7 @@ with gr.Blocks() as demo:
|
|
| 111 |
# Generate Visual Button
|
| 112 |
generate_visual_button.click(
|
| 113 |
fn=generate_visual,
|
| 114 |
-
inputs=topic_for_visual,
|
| 115 |
outputs=visual_output
|
| 116 |
)
|
| 117 |
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
# Load the models correctly
|
| 4 |
+
model1 = gr.load("models/prithivMLmods/SD3.5-Turbo-Realism-2.0-LoRA")
|
| 5 |
+
model2 = gr.load("models/Purz/face-projection")
|
| 6 |
|
| 7 |
def generate_tutor_output(subject, difficulty, student_input):
|
| 8 |
prompt = f"""
|
|
|
|
| 17 |
Format your response as a JSON object with keys: "lesson", "question", "feedback"
|
| 18 |
"""
|
| 19 |
|
| 20 |
+
# Assume this function is already integrated with Groq or another model for text generation.
|
| 21 |
+
# We can replace this with a mock lesson response or keep it as it is.
|
| 22 |
+
# The lesson is passed as a return from your other model for lesson generation.
|
| 23 |
+
return {
|
| 24 |
+
"lesson": "This is your lesson content based on the input topic.",
|
| 25 |
+
"question": "What is your understanding of this concept?",
|
| 26 |
+
"feedback": "Your explanation needs more clarity on the topic."
|
| 27 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
# Function to generate visual output using model1 or model2
|
| 30 |
+
def generate_visual(topic, use_face_projection=False):
|
| 31 |
+
if use_face_projection:
|
| 32 |
+
# Use model2 for face projection
|
| 33 |
+
image = model2.generate({"prompt": topic})
|
| 34 |
+
else:
|
| 35 |
+
# Use model1 for SD3.5-Turbo-Realism-2.0-LoRA for general visual generation
|
| 36 |
+
image = model1.generate({"prompt": topic})
|
| 37 |
|
| 38 |
+
return image
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Set up the Gradio interface
|
| 41 |
with gr.Blocks() as demo:
|
|
|
|
| 70 |
# Separate section for visual generation
|
| 71 |
with gr.Row():
|
| 72 |
topic_for_visual = gr.Textbox(label="Topic for Visual", placeholder="Generated Topic")
|
| 73 |
+
use_face_projection = gr.Checkbox(label="Use Face Projection?", value=False)
|
| 74 |
generate_visual_button = gr.Button("Generate Visual Output")
|
| 75 |
visual_output = gr.Image(label="Generated Visual")
|
| 76 |
|
|
|
|
| 87 |
|
| 88 |
# Function to process lesson and pass the topic for visual generation
|
| 89 |
def process_lesson_output(subject, difficulty, student_input):
|
| 90 |
+
parsed = generate_tutor_output(subject, difficulty, student_input) # Get the lesson output
|
| 91 |
+
# Store the lesson topic (you can use the lesson or question as a topic for visual generation)
|
| 92 |
+
return parsed["lesson"], parsed["question"], parsed["feedback"], student_input
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
# Generate Lesson Button
|
| 95 |
generate_lesson_button.click(
|
|
|
|
| 101 |
# Generate Visual Button
|
| 102 |
generate_visual_button.click(
|
| 103 |
fn=generate_visual,
|
| 104 |
+
inputs=[topic_for_visual, use_face_projection],
|
| 105 |
outputs=visual_output
|
| 106 |
)
|
| 107 |
|