yasserrmd commited on
Commit
2554d32
·
verified ·
1 Parent(s): 2445961

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -1,12 +1,15 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os # For environment variables
 
4
 
5
  # Initialize the Hugging Face Inference Client
6
  client = InferenceClient()
7
 
8
- # Generator function for streaming AI response
9
  def generate_response(prompt_template, **kwargs):
 
 
10
  prompt = os.getenv(prompt_template).format(**kwargs)
11
  response = client.chat.completions.create(
12
  model="Qwen/Qwen2.5-Math-1.5B-Instruct",
@@ -15,12 +18,13 @@ def generate_response(prompt_template, **kwargs):
15
  max_tokens=1024,
16
  top_p=0.8
17
  )
18
- return response.choices[0].message["content"]
 
19
 
20
  # Gradio app interface
21
  with gr.Blocks() as app:
22
  gr.Markdown("## Mathematical Insight Tutor")
23
- gr.Markdown("An advanced AI-powered tutor to help you master math concepts with step-by-step explanations and LaTeX rendering.")
24
 
25
  def create_tab(tab_name, prompt_template, inputs):
26
  with gr.Tab(tab_name):
@@ -105,4 +109,4 @@ app.css = """
105
  """
106
 
107
  # Launch the app
108
- app.launch(debug=True)
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os # For environment variables
4
+ import time # To simulate processing time if needed
5
 
6
  # Initialize the Hugging Face Inference Client
7
  client = InferenceClient()
8
 
9
+ # Function to generate and format AI response
10
  def generate_response(prompt_template, **kwargs):
11
+ # Simulate processing/loading
12
+ time.sleep(1) # Optional: Remove or adjust based on actual execution time
13
  prompt = os.getenv(prompt_template).format(**kwargs)
14
  response = client.chat.completions.create(
15
  model="Qwen/Qwen2.5-Math-1.5B-Instruct",
 
18
  max_tokens=1024,
19
  top_p=0.8
20
  )
21
+ response_content = response.choices[0].message["content"]
22
+ return gr.update(value=f"${response_content}$")
23
 
24
  # Gradio app interface
25
  with gr.Blocks() as app:
26
  gr.Markdown("## Mathematical Insight Tutor")
27
+ gr.Markdown("An advanced AI-powered tutor to help you master math concepts with step-by-step explanations.")
28
 
29
  def create_tab(tab_name, prompt_template, inputs):
30
  with gr.Tab(tab_name):
 
109
  """
110
 
111
  # Launch the app
112
+ app.launch(debug=True)