SameerArz commited on
Commit
b95597f
·
verified ·
1 Parent(s): c295df7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -35
app.py CHANGED
@@ -1,9 +1,8 @@
1
  import gradio as gr
2
- from groq import Groq
3
- import os
4
 
5
- # Initialize Groq client with your API key
6
- client = Groq(api_key=os.environ["GROQ_API_KEY"])
 
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
- completion = client.chat.completions.create(
22
- messages=[
23
- {
24
- "role": "system",
25
- "content": "You are the world's best AI tutor, renowned for your ability to explain complex concepts in an engaging, clear, and memorable way and giving math examples. Your expertise in {subject} is unparalleled, and you're adept at tailoring your teaching to {difficulty} level students. Your goal is to not just impart knowledge, but to inspire a love for learning and critical thinking.",
26
- },
27
- {
28
- "role": "user",
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 (image) based on the lesson/topic
39
- def generate_visual(topic):
40
- # You can integrate your image generation model here.
41
- # For simplicity, let's assume you have an image generation model available.
42
- # Here's an example where we generate a simple placeholder image based on the topic.
 
 
 
43
 
44
- # Example image generation logic (you can replace this with your actual model).
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
- try:
98
- parsed = eval(generate_tutor_output(subject, difficulty, student_input)) # Convert string to dictionary
99
- # Store the lesson topic (you can use the lesson or question as a topic for visual generation)
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