manaf1234 commited on
Commit
91c720f
·
verified ·
1 Parent(s): ddb79ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import torch
3
  from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
4
  from threading import Thread
 
5
 
6
  # 1. Load weights explicitly
7
  MODEL_ID = "Axiom-AI/Quasar-1-0.8B"
@@ -46,7 +47,7 @@ def generate_response(message, history, system_prompt, temperature, top_p, top_k
46
  # Setup standard base template structures
47
  prompt = f"System: {system_prompt}\n" if system_prompt else ""
48
 
49
- # Pack up chat context from Gradio 6's dictionary format
50
  for turn in history:
51
  role = turn.get("role")
52
  content = turn.get("content")
@@ -54,12 +55,9 @@ def generate_response(message, history, system_prompt, temperature, top_p, top_k
54
  prompt += f"User: {content}\n"
55
  elif role == "assistant":
56
  # Strip out our custom HTML formatting back to raw tokens for context history
57
- # (Simple fallback: if the history already has html, you might want to keep a raw text history,
58
- # but for this generation block we clean basic tags if present)
59
  clean_content = content
60
  if "🤔" in content:
61
  # Reconstruct rough raw tags for the model's history context
62
- import re
63
  clean_content = re.sub(r'<details.*?>.*?<\/summary>', '<think>', clean_content)
64
  clean_content = clean_content.replace('</div></details>', '</think>')
65
  clean_content = re.sub(r'<div.*?>', '', clean_content)
@@ -87,7 +85,6 @@ def generate_response(message, history, system_prompt, temperature, top_p, top_k
87
  partial_text = "<think>"
88
  for new_text in streamer:
89
  partial_text += new_text
90
- # Yield the beautifully formatted text instead of raw markdown tags
91
  yield format_reasoning(partial_text)
92
 
93
  # 3. Clean Interface Assembly
@@ -97,8 +94,8 @@ with gr.Blocks() as demo:
97
  with gr.Row():
98
  # Left Workspace Column: Chat Layout
99
  with gr.Column(scale=3):
100
- # Line wrapping and markdown parsing enabled by default
101
- chatbot = gr.Chatbot(height=500, type="messages")
102
  msg_input = gr.Textbox(placeholder="Enter reasoning prompt...", label="Your Message")
103
  with gr.Row():
104
  submit_btn = gr.Button("Send", variant="primary")
@@ -117,7 +114,7 @@ with gr.Blocks() as demo:
117
  top_k = gr.Slider(minimum=1, maximum=100, value=40, step=1, label="Top-K")
118
  max_tokens = gr.Slider(minimum=64, maximum=2048, value=1024, step=64, label="Max New Tokens")
119
 
120
- # Gradio 6 explicit dictionary append functions
121
  def user_side_submit(user_message, history):
122
  history.append({"role": "user", "content": user_message})
123
  return "", history
 
2
  import torch
3
  from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
4
  from threading import Thread
5
+ import re
6
 
7
  # 1. Load weights explicitly
8
  MODEL_ID = "Axiom-AI/Quasar-1-0.8B"
 
47
  # Setup standard base template structures
48
  prompt = f"System: {system_prompt}\n" if system_prompt else ""
49
 
50
+ # Pack up chat context from the dictionary format
51
  for turn in history:
52
  role = turn.get("role")
53
  content = turn.get("content")
 
55
  prompt += f"User: {content}\n"
56
  elif role == "assistant":
57
  # Strip out our custom HTML formatting back to raw tokens for context history
 
 
58
  clean_content = content
59
  if "🤔" in content:
60
  # Reconstruct rough raw tags for the model's history context
 
61
  clean_content = re.sub(r'<details.*?>.*?<\/summary>', '<think>', clean_content)
62
  clean_content = clean_content.replace('</div></details>', '</think>')
63
  clean_content = re.sub(r'<div.*?>', '', clean_content)
 
85
  partial_text = "<think>"
86
  for new_text in streamer:
87
  partial_text += new_text
 
88
  yield format_reasoning(partial_text)
89
 
90
  # 3. Clean Interface Assembly
 
94
  with gr.Row():
95
  # Left Workspace Column: Chat Layout
96
  with gr.Column(scale=3):
97
+ # REMOVED type="messages" to solve the init crash
98
+ chatbot = gr.Chatbot(height=500)
99
  msg_input = gr.Textbox(placeholder="Enter reasoning prompt...", label="Your Message")
100
  with gr.Row():
101
  submit_btn = gr.Button("Send", variant="primary")
 
114
  top_k = gr.Slider(minimum=1, maximum=100, value=40, step=1, label="Top-K")
115
  max_tokens = gr.Slider(minimum=64, maximum=2048, value=1024, step=64, label="Max New Tokens")
116
 
117
+ # Gradio dictionary append functions
118
  def user_side_submit(user_message, history):
119
  history.append({"role": "user", "content": user_message})
120
  return "", history