mgbam commited on
Commit
a14fe7d
·
verified ·
1 Parent(s): 5203e07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -75
app.py CHANGED
@@ -1,75 +1,53 @@
1
- import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- # Initialize the Hugging Face Inference Client
5
- client = InferenceClient()
6
-
7
- # Function to optimize code or simplify mathematical logic
8
- def optimize_or_simplify(input_text, task_type):
9
- """
10
- Optimizes a given code snippet or simplifies a mathematical expression based on the selected task.
11
-
12
- Args:
13
- input_text (str): The user-provided code or math expression.
14
- task_type (str): The type of task ('Code Optimization' or 'Math Simplification').
15
-
16
- Returns:
17
- str: The optimized code or simplified mathematical result.
18
- """
19
- if task_type == "Code Optimization":
20
- prompt = (
21
- f"Optimize the following code for performance and readability. "
22
- f"Provide detailed suggestions and refactor the code:\n\n{input_text}"
23
- )
24
- else: # Math Simplification
25
- prompt = (
26
- f"Simplify the following mathematical expression or algorithm, "
27
- f"ensuring accuracy and efficiency:\n\n{input_text}"
28
- )
29
-
30
- # Call the Hugging Face model
31
- response = client.chat.completions.create(
32
- model="Qwen/Qwen2.5-Coder-32B-Instruct",
33
- messages=[{"role": "user", "content": prompt}],
34
- temperature=0.5,
35
- max_tokens=512
36
- )
37
- return response["choices"][0]["message"]["content"]
38
-
39
- # Create Gradio interface
40
- with gr.Blocks() as app:
41
- gr.Markdown("## Code Optimization and Math Simplification Assistant")
42
- gr.Markdown(
43
- "Refine your code for better performance or simplify complex mathematical expressions effortlessly. "
44
- "Choose a task and input your text to get started!"
45
- )
46
-
47
- with gr.Row():
48
- # Input section
49
- with gr.Column():
50
- task_type = gr.Radio(
51
- choices=["Code Optimization", "Math Simplification"],
52
- label="Select Task",
53
- value="Code Optimization"
54
- )
55
- input_text = gr.Textbox(
56
- lines=10,
57
- label="Input Text",
58
- placeholder="Enter your code or mathematical expression here"
59
- )
60
- process_button = gr.Button("Process")
61
-
62
- # Output section
63
- with gr.Column():
64
- gr.Markdown("### Output")
65
- output_result = gr.Textbox(lines=15, interactive=False)
66
-
67
- # Link button to function
68
- process_button.click(
69
- fn=optimize_or_simplify,
70
- inputs=[input_text, task_type],
71
- outputs=output_result
72
- )
73
-
74
- # Launch the app
75
- app.launch()
 
1
+ import gradio as gr
2
+
3
+ # Define learning paths and corresponding content
4
+ learning_paths = {
5
+ "Math": "Welcome to the Math path! Solve problems and explore concepts like algebra, calculus, and geometry.",
6
+ "Science & Engineering": "Dive into physics, chemistry, and engineering concepts with interactive examples.",
7
+ "Computer Science & Programming": "Learn programming, algorithms, and computer science fundamentals.",
8
+ "Data Science & Data Analysis": "Master data manipulation, visualization, and analysis techniques."
9
+ }
10
+
11
+ # Function to display the selected learning path's content
12
+ def show_learning_content(selected_path):
13
+ """
14
+ Displays content for the selected learning path.
15
+ """
16
+ return f"You selected: {selected_path}\n\n{learning_paths[selected_path]}"
17
+
18
+ # Function to simulate feedback or progression
19
+ def provide_feedback(selected_path):
20
+ return f"Great choice! Let's dive into {selected_path}."
21
+
22
+ # Gradio interface
23
+ with gr.Blocks() as app:
24
+ gr.Markdown("## Interactive Learning Platform")
25
+ gr.Markdown("Choose a topic to start learning:")
26
+
27
+ # Progress bar at the top
28
+ gr.Markdown('<div style="width: 100%; background-color: lightgray; height: 5px; border-radius: 5px;">'
29
+ '<div style="width: 25%; background-color: green; height: 100%;"></div></div>',
30
+ unsafe_allow_html=True)
31
+
32
+ # Options for learning paths
33
+ selected_topic = gr.Radio(
34
+ choices=list(learning_paths.keys()),
35
+ label="Select a Learning Path",
36
+ value="Math"
37
+ )
38
+
39
+ # Buttons for user interaction
40
+ with gr.Row():
41
+ continue_button = gr.Button("Continue")
42
+ feedback_button = gr.Button("Get Feedback")
43
+
44
+ # Outputs
45
+ learning_output = gr.Textbox(lines=8, interactive=False, label="Learning Content")
46
+ feedback_output = gr.Textbox(interactive=False, label="Feedback")
47
+
48
+ # Link interactions to actions
49
+ continue_button.click(fn=show_learning_content, inputs=selected_topic, outputs=learning_output)
50
+ feedback_button.click(fn=provide_feedback, inputs=selected_topic, outputs=feedback_output)
51
+
52
+ # Launch the app
53
+ app.launch()