FractalAIR commited on
Commit
71be435
·
verified ·
1 Parent(s): 4ca4ad0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -25
app.py CHANGED
@@ -6,25 +6,17 @@ from threading import Thread
6
  import re
7
  import uuid
8
  from openai import OpenAI
9
- import requests
10
- from io import BytesIO
11
- import os
12
- #from PIL import Image
13
 
14
  client = OpenAI(
15
  base_url="https://a7g1ajqixo23revq.us-east-1.aws.endpoints.huggingface.cloud/v1/",
16
  api_key="hf_XXXXX"
17
  )
18
 
19
- from PIL import Image
20
- from pix2tex import cli as pix2tex
21
- # Load model once to avoid re-init every time
22
- ocr_model = pix2tex.LatexOCR()
23
- def image_to_latex(image_path):
24
- image = Image.open(image_path).convert("RGB")
25
- return ocr_model(image)
26
 
27
-
28
  # Global dictionary to store all conversations: {id: {"title": str, "messages": list}}
29
  conversations = {}
30
 
@@ -43,11 +35,7 @@ def generate_response(user_message,
43
  if not user_message.strip():
44
  return history_state, history_state
45
 
46
- system_message = (
47
- "You are Ramanujan Ganit R1, a state-of-the-art math reasoning assistant created by Fractal AI Research. "
48
- "You specialize in solving complex mathematics and science problems with step-by-step reasoning. "
49
- "You are *not* ChatGPT, OpenAI, or DeepSeek. If asked about your identity, always say you are Ramanujan Ganit R1 developed by Fractal AI Research."
50
- )
51
  messages = [{"role": "system", "content": system_message}]
52
  for m in history_state:
53
  messages.append({"role": m["role"], "content": m["content"]})
@@ -162,19 +150,11 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
162
  with gr.Column(scale=4):
163
  #chatbot = gr.Chatbot(label="Chat", type="messages")
164
  chatbot = gr.Chatbot(label="Chat", type="messages", height=520)
165
-
166
  with gr.Row():
167
  user_input = gr.Textbox(label="User Input", placeholder="Type your question here...", lines=3, scale=8)
168
  with gr.Column():
169
  submit_button = gr.Button("Send", variant="primary", scale=1)
170
  clear_button = gr.Button("Clear", scale=1)
171
-
172
- with gr.Row():
173
- image_input = gr.Image(type="filepath", label="Upload Image")
174
- output_text = gr.Textbox(label="LaTeX Output")
175
- image_input.change(fn=image_to_latex, inputs=image_input, outputs=output_text)
176
-
177
-
178
  gr.Markdown("**Try these examples:**")
179
  with gr.Row():
180
  example1_button = gr.Button("JEE Main 2025\nCombinatorics")
 
6
  import re
7
  import uuid
8
  from openai import OpenAI
 
 
 
 
9
 
10
  client = OpenAI(
11
  base_url="https://a7g1ajqixo23revq.us-east-1.aws.endpoints.huggingface.cloud/v1/",
12
  api_key="hf_XXXXX"
13
  )
14
 
15
+ def format_math(text):
16
+ text = re.sub(r"\[(.*?)\]", r"$$\1$$", text, flags=re.DOTALL)
17
+ text = text.replace(r"\(", "$").replace(r"\)", "$")
18
+ return text
 
 
 
19
 
 
20
  # Global dictionary to store all conversations: {id: {"title": str, "messages": list}}
21
  conversations = {}
22
 
 
35
  if not user_message.strip():
36
  return history_state, history_state
37
 
38
+ system_message = "Your role as an assistant..."
 
 
 
 
39
  messages = [{"role": "system", "content": system_message}]
40
  for m in history_state:
41
  messages.append({"role": m["role"], "content": m["content"]})
 
150
  with gr.Column(scale=4):
151
  #chatbot = gr.Chatbot(label="Chat", type="messages")
152
  chatbot = gr.Chatbot(label="Chat", type="messages", height=520)
 
153
  with gr.Row():
154
  user_input = gr.Textbox(label="User Input", placeholder="Type your question here...", lines=3, scale=8)
155
  with gr.Column():
156
  submit_button = gr.Button("Send", variant="primary", scale=1)
157
  clear_button = gr.Button("Clear", scale=1)
 
 
 
 
 
 
 
158
  gr.Markdown("**Try these examples:**")
159
  with gr.Row():
160
  example1_button = gr.Button("JEE Main 2025\nCombinatorics")