SameerArz commited on
Commit
d7bc483
·
verified ·
1 Parent(s): 623c7aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -57
app.py CHANGED
@@ -47,44 +47,14 @@ def generate_tutor_output(subject, difficulty, student_input, selected_model):
47
  except Exception as e:
48
  return f"Error: {str(e)}"
49
 
50
- # Inline CSS for styling the Gradio interface
51
  custom_css = """
52
  body {
53
  font-family: 'Poppins', sans-serif;
54
- background-color: #f4f4f9;
55
- color: #333;
56
  }
57
- .container {
58
- display: flex;
59
- flex-direction: row;
60
- height: 100vh;
61
- overflow: hidden;
62
- }
63
- .text-section, .image-section {
64
- flex: 1;
65
- padding: 20px;
66
- overflow-y: auto;
67
- }
68
- .text-section {
69
- background-color: #fff;
70
- border-right: 1px solid #ddd;
71
- }
72
- .image-section {
73
- background-color: #f9f9f9;
74
- }
75
- .fullframe {
76
- width: 100%;
77
- height: 60vh;
78
- overflow: hidden;
79
- }
80
- .iframe-element {
81
- width: 100%;
82
- height: 100%;
83
- }
84
- h2 {
85
  font-size: 24px;
86
  margin-bottom: 20px;
87
- color: #444;
88
  }
89
  label {
90
  font-weight: 600;
@@ -114,7 +84,7 @@ button {
114
  button:hover {
115
  background-color: #45a049;
116
  }
117
- .response-box {
118
  margin-top: 20px;
119
  padding: 15px;
120
  background-color: #f1f1f1;
@@ -153,15 +123,15 @@ button:hover {
153
 
154
  # Gradio interface
155
  with gr.Blocks(
156
- title="AI Tutor with Text and Image Generation",
157
- css=custom_css # Use inline CSS
158
  ) as demo:
159
- gr.Markdown("# 🎓 Your AI Tutor with Text and Image Generation")
160
 
161
- with gr.Row(elem_classes="container"):
162
- # Text Generation Section
163
- with gr.Column(scale=2, elem_classes="text-section"):
164
- gr.Markdown("## Text Generation with Groq API")
165
  subject = gr.Dropdown(
166
  ["Math", "Science", "History", "Literature", "Code", "AI"],
167
  label="Subject",
@@ -185,23 +155,23 @@ with gr.Blocks(
185
  )
186
  submit_button_text = gr.Button("Generate Lesson & Question", variant="primary")
187
 
188
- # Text Output Section
189
- with gr.Column(scale=3, elem_classes="text-section"):
190
- lesson_output = gr.Markdown(label="Lesson", elem_classes="response-box")
191
- question_output = gr.Markdown(label="Comprehension Question", elem_classes="response-box")
192
- feedback_output = gr.Markdown(label="Feedback", elem_classes="response-box")
193
 
194
- # Image Generation Section (using iframe)
195
- with gr.Row(elem_classes="container"):
196
- with gr.Column(scale=1, elem_classes="image-section"):
 
197
  gr.Markdown("## Image Generation")
198
  gr.Markdown("Use the embedded tool below to generate images.")
199
- with gr.Column(scale=4, elem_classes="image-section"):
200
- gr.HTML("""
201
- <div class="fullframe">
202
- <iframe class="iframe-element" allowfullscreen="true" frameborder="0" src="https://artificialguybr-realvisxl-free-demo.hf.space"></iframe>
203
- </div>
204
- """)
205
 
206
  gr.HTML("""
207
  <a href="https://discord.com/invite/EM4uHQrakm" class="floating-button" target="_blank">
@@ -211,9 +181,9 @@ with gr.Blocks(
211
 
212
  gr.Markdown("""
213
  ### How to Use
214
- 1. **Text Section**: Select a subject, difficulty, and model, type your query, and click 'Generate Lesson & Question'.
215
- 2. **Image Section**: Use the embedded image generation tool to create visuals.
216
- 3. Review the AI-generated content!
217
 
218
  *Example*: Try "Explain the quicksort algorithm" for text, and use the image tool to generate "a photo of an astronaut riding a horse on mars".
219
  """)
@@ -226,10 +196,23 @@ with gr.Blocks(
226
  except Exception as e:
227
  return f"Error: {str(e)}", "No question available", "No feedback available"
228
 
 
 
 
 
 
 
229
  submit_button_text.click(
230
  fn=process_output_text,
231
  inputs=[subject, difficulty, student_input, model_selector],
232
  outputs=[lesson_output, question_output, feedback_output]
233
  )
234
 
 
 
 
 
 
 
 
235
  demo.launch()
 
47
  except Exception as e:
48
  return f"Error: {str(e)}"
49
 
50
+ # Inline CSS to match the original styling
51
  custom_css = """
52
  body {
53
  font-family: 'Poppins', sans-serif;
 
 
54
  }
55
+ h1 {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  font-size: 24px;
57
  margin-bottom: 20px;
 
58
  }
59
  label {
60
  font-weight: 600;
 
84
  button:hover {
85
  background-color: #45a049;
86
  }
87
+ .markdown-output {
88
  margin-top: 20px;
89
  padding: 15px;
90
  background-color: #f1f1f1;
 
123
 
124
  # Gradio interface
125
  with gr.Blocks(
126
+ title="AI Tutor with Text and Visuals",
127
+ css=custom_css
128
  ) as demo:
129
+ gr.Markdown("# 🎓 Your AI Tutor with Visuals & Images")
130
 
131
+ # Section for generating Text-based output
132
+ with gr.Row():
133
+ with gr.Column(scale=2):
134
+ # Input fields for subject, difficulty, model, and student input
135
  subject = gr.Dropdown(
136
  ["Math", "Science", "History", "Literature", "Code", "AI"],
137
  label="Subject",
 
155
  )
156
  submit_button_text = gr.Button("Generate Lesson & Question", variant="primary")
157
 
158
+ with gr.Column(scale=3):
159
+ # Output fields for lesson, question, and feedback
160
+ lesson_output = gr.Markdown(label="Lesson", elem_classes="markdown-output")
161
+ question_output = gr.Markdown(label="Comprehension Question", elem_classes="markdown-output")
162
+ feedback_output = gr.Markdown(label="Feedback", elem_classes="markdown-output")
163
 
164
+ # Section for Visual output using iframe
165
+ with gr.Row():
166
+ with gr.Column(scale=2):
167
+ # Note: We're using an iframe, so we don't need a model selector for image generation
168
  gr.Markdown("## Image Generation")
169
  gr.Markdown("Use the embedded tool below to generate images.")
170
+ submit_button_visual = gr.Button("Open Visual Tool", variant="primary")
171
+
172
+ with gr.Column(scale=3):
173
+ # Output field for the iframe
174
+ visual_output = gr.HTML(label="Image Generation Tool")
 
175
 
176
  gr.HTML("""
177
  <a href="https://discord.com/invite/EM4uHQrakm" class="floating-button" target="_blank">
 
181
 
182
  gr.Markdown("""
183
  ### How to Use
184
+ 1. **Text Section**: Select a subject, difficulty, and model, type your query, and click 'Generate Lesson & Question' to get your personalized lesson, comprehension question, and feedback.
185
+ 2. **Visual Section**: Click 'Open Visual Tool' to load the image generation tool, then use it to generate images.
186
+ 3. Review the AI-generated content to enhance your learning experience!
187
 
188
  *Example*: Try "Explain the quicksort algorithm" for text, and use the image tool to generate "a photo of an astronaut riding a horse on mars".
189
  """)
 
196
  except Exception as e:
197
  return f"Error: {str(e)}", "No question available", "No feedback available"
198
 
199
+ def load_visual_tool():
200
+ return """
201
+ <iframe style="width: 100%; height: 500px;" allowfullscreen="true" frameborder="0" src="https://artificialguybr-realvisxl-free-demo.hf.space"></iframe>
202
+ """
203
+
204
+ # Generate Text-based Output
205
  submit_button_text.click(
206
  fn=process_output_text,
207
  inputs=[subject, difficulty, student_input, model_selector],
208
  outputs=[lesson_output, question_output, feedback_output]
209
  )
210
 
211
+ # Load Visual Tool (iframe)
212
+ submit_button_visual.click(
213
+ fn=load_visual_tool,
214
+ inputs=[],
215
+ outputs=[visual_output]
216
+ )
217
+
218
  demo.launch()