| import gradio as gr |
| from huggingface_hub import InferenceClient |
|
|
| |
| client = InferenceClient() |
|
|
| |
| def generate_content(selected_path): |
| """ |
| Generates dynamic content based on the selected learning path using an NLP model. |
| """ |
| prompt = f"Create a short lesson or problem for the topic: {selected_path}." |
| response = client.text_generation( |
| model="gpt2", |
| inputs=prompt, |
| max_new_tokens=150, |
| temperature=0.7 |
| ) |
| return response["generated_text"] |
|
|
| |
| def evaluate_answer(user_input, selected_path): |
| """ |
| Evaluates user input using the model and provides feedback. |
| """ |
| prompt = f"Evaluate the following response for {selected_path}:\n\nUser Answer: {user_input}\nProvide feedback." |
| response = client.text_generation( |
| model="gpt2", |
| inputs=prompt, |
| max_new_tokens=100, |
| temperature=0.5 |
| ) |
| return response["generated_text"] |
|
|
| |
| with gr.Blocks() as app: |
| gr.Markdown("## AI-Powered Learning Platform") |
| gr.Markdown("Choose a topic to start learning:") |
| |
| |
| gr.HTML('<div style="width: 100%; background-color: lightgray; height: 5px; border-radius: 5px;">' |
| '<div style="width: 25%; background-color: green; height: 100%;"></div></div>') |
| |
| |
| selected_topic = gr.Radio( |
| choices=["Math", "Science & Engineering", "Computer Science & Programming", "Data Science & Data Analysis"], |
| label="Select a Learning Path", |
| value="Math" |
| ) |
| |
| |
| with gr.Row(): |
| generate_button = gr.Button("Generate Content") |
| submit_answer_button = gr.Button("Submit Answer") |
|
|
| |
| content_output = gr.Textbox(lines=8, interactive=False, label="Generated Content") |
| answer_input = gr.Textbox(lines=2, label="Your Answer") |
| feedback_output = gr.Textbox(interactive=False, label="Feedback") |
|
|
| |
| generate_button.click(fn=generate_content, inputs=selected_topic, outputs=content_output) |
| submit_answer_button.click(fn=evaluate_answer, inputs=[answer_input, selected_topic], outputs=feedback_output) |
|
|
| |
| app.launch() |
|
|