RamishRasool14 commited on
Commit ·
9c1566d
1
Parent(s): a765a0a
fix
Browse files
app.py
CHANGED
|
@@ -14,11 +14,11 @@ FastLanguageModel.for_inference(model) # Enable optimized inference
|
|
| 14 |
|
| 15 |
def predict(question, history):
|
| 16 |
history = history or []
|
| 17 |
-
history.append({"
|
| 18 |
|
| 19 |
inputs = tokenizer(
|
| 20 |
tokenizer.apply_chat_template(
|
| 21 |
-
|
| 22 |
tokenize=False,
|
| 23 |
add_generation_prompt=True
|
| 24 |
),
|
|
@@ -32,27 +32,33 @@ def predict(question, history):
|
|
| 32 |
partial_text += next_token
|
| 33 |
yield partial_text
|
| 34 |
|
| 35 |
-
history.append({"
|
| 36 |
return history
|
| 37 |
|
| 38 |
# Create the Gradio interface with Markdown support
|
| 39 |
-
with gr.Blocks() as iface:
|
| 40 |
chatbot = gr.Chatbot(
|
| 41 |
show_label=False,
|
| 42 |
container=True,
|
| 43 |
height=600,
|
| 44 |
bubble_full_width=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
)
|
|
|
|
| 46 |
msg = gr.Textbox(
|
| 47 |
label="Message",
|
| 48 |
-
placeholder="Type your message here...",
|
| 49 |
lines=2
|
| 50 |
)
|
| 51 |
clear = gr.Button("Clear")
|
| 52 |
|
| 53 |
state = gr.State([])
|
| 54 |
|
| 55 |
-
|
| 56 |
predict,
|
| 57 |
[msg, state],
|
| 58 |
[chatbot, state],
|
|
|
|
| 14 |
|
| 15 |
def predict(question, history):
|
| 16 |
history = history or []
|
| 17 |
+
history.append({"from": "human", "value": question})
|
| 18 |
|
| 19 |
inputs = tokenizer(
|
| 20 |
tokenizer.apply_chat_template(
|
| 21 |
+
history,
|
| 22 |
tokenize=False,
|
| 23 |
add_generation_prompt=True
|
| 24 |
),
|
|
|
|
| 32 |
partial_text += next_token
|
| 33 |
yield partial_text
|
| 34 |
|
| 35 |
+
history.append({"from": "gpt", "value": partial_text})
|
| 36 |
return history
|
| 37 |
|
| 38 |
# Create the Gradio interface with Markdown support
|
| 39 |
+
with gr.Blocks(css=".message { white-space: pre-wrap; }") as iface:
|
| 40 |
chatbot = gr.Chatbot(
|
| 41 |
show_label=False,
|
| 42 |
container=True,
|
| 43 |
height=600,
|
| 44 |
bubble_full_width=False,
|
| 45 |
+
render_markdown=True, # Enable markdown rendering
|
| 46 |
+
latex_delimiters=[ # Optional: Enable LaTeX rendering
|
| 47 |
+
{"left": "$$", "right": "$$", "display": True},
|
| 48 |
+
{"left": "$", "right": "$", "display": False},
|
| 49 |
+
],
|
| 50 |
)
|
| 51 |
+
submit = gr.Button("Submit")
|
| 52 |
msg = gr.Textbox(
|
| 53 |
label="Message",
|
| 54 |
+
placeholder="Type your message here... (Markdown supported)",
|
| 55 |
lines=2
|
| 56 |
)
|
| 57 |
clear = gr.Button("Clear")
|
| 58 |
|
| 59 |
state = gr.State([])
|
| 60 |
|
| 61 |
+
submit.click(
|
| 62 |
predict,
|
| 63 |
[msg, state],
|
| 64 |
[chatbot, state],
|