Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -73,87 +73,31 @@ def chat_fn(message, history, system_text, temperature, top_p, max_new, min_new)
|
|
| 73 |
reply = tokenizer.batch_decode(new_tokens, skip_special_tokens=True)[0].strip()
|
| 74 |
return reply
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
if not history:
|
| 81 |
-
return "" # nothing to answer
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
# Call your existing generator with sane defaults
|
| 88 |
-
return chat_fn(
|
| 89 |
-
message=last_user_msg,
|
| 90 |
-
history=prior_history,
|
| 91 |
-
system_text=system_text,
|
| 92 |
-
temperature=0.7,
|
| 93 |
-
top_p=0.9,
|
| 94 |
-
max_new=512,
|
| 95 |
-
min_new=128,
|
| 96 |
)
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
return response
|
| 102 |
-
|
| 103 |
-
with gr.Blocks(css="""
|
| 104 |
-
.gradio-container {
|
| 105 |
-
max-width: 600px;
|
| 106 |
-
margin: auto;
|
| 107 |
-
padding: 20px;
|
| 108 |
-
font-family: sans-serif;
|
| 109 |
-
position: relative;
|
| 110 |
-
}
|
| 111 |
-
.chatbot {
|
| 112 |
-
height: 500px !important;
|
| 113 |
-
overflow-y: auto;
|
| 114 |
-
}
|
| 115 |
-
.corner {
|
| 116 |
-
position: fixed;
|
| 117 |
-
bottom: 2px;
|
| 118 |
-
z-index: 9999;
|
| 119 |
-
pointer-events: none;
|
| 120 |
-
}
|
| 121 |
-
#left { left: 2px; }
|
| 122 |
-
#right { right: 2px; }
|
| 123 |
-
.corner img {
|
| 124 |
-
height: 500px; /* fixed height */
|
| 125 |
-
width: auto; /* auto to keep aspect ratio */
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
""") as demo:
|
| 129 |
-
gr.Markdown(
|
| 130 |
-
"""
|
| 131 |
-
<div style='text-align: center; padding: 10px;'>
|
| 132 |
-
<h1 style='font-size: 2.2em; margin-bottom: 0.2em;'>🤖 <span style='color: #4F46E5;'>kRISHNA.ai</span></h1>
|
| 133 |
-
<p style='font-size: 1.1em; color: #555;'>5000-Years of Ancient WISDOM with Modern AI ✨</p>
|
| 134 |
-
</div>
|
| 135 |
-
""",
|
| 136 |
-
elem_id="header"
|
| 137 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
chat = gr.ChatInterface(
|
| 139 |
fn=gradio_fn,
|
| 140 |
-
|
| 141 |
-
"Hello!",
|
| 142 |
-
"How can I overcome fear of failure?",
|
| 143 |
-
"How do I forgive someone who hurt me deeply?",
|
| 144 |
-
"What can I do to stop overthinking?"
|
| 145 |
-
],
|
| 146 |
chatbot=gr.Chatbot(elem_classes="chatbot"),
|
| 147 |
-
theme="compact",
|
| 148 |
)
|
| 149 |
-
gr.HTML(f"""
|
| 150 |
-
<div id="left" class="corner">
|
| 151 |
-
<img src="">
|
| 152 |
-
</div>
|
| 153 |
-
<div id="right" class="corner">
|
| 154 |
-
<img src="">
|
| 155 |
-
</div>
|
| 156 |
-
""")
|
| 157 |
|
| 158 |
if __name__ == "__main__":
|
| 159 |
demo.launch()
|
|
|
|
| 73 |
reply = tokenizer.batch_decode(new_tokens, skip_special_tokens=True)[0].strip()
|
| 74 |
return reply
|
| 75 |
|
| 76 |
+
# Wrap for ChatInterface + ZeroGPU
|
| 77 |
+
@spaces.GPU() # REQUIRED for ZeroGPU; remove if using standard GPU hardware
|
| 78 |
+
def gradio_fn(message, history, system_text, temperature, top_p, max_new, min_new):
|
| 79 |
+
return chat_fn(message, history, system_text, temperature, top_p, max_new, min_new)
|
|
|
|
|
|
|
| 80 |
|
| 81 |
+
with gr.Blocks() as demo:
|
| 82 |
+
gr.Markdown(
|
| 83 |
+
"<h1 style='text-align:center'>Gita Assistant (Qwen2.5-3B Fine-tuned)</h1>"
|
| 84 |
+
"<p style='text-align:center'>Ask in English / हिंदी / ગુજરાતી. The assistant cites verses when relevant.</p>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
)
|
| 86 |
|
| 87 |
+
system_box = gr.Textbox(
|
| 88 |
+
value="Reply in the user’s language with 2–3 concise points (200–400 words); cite Gita verses when relevant.",
|
| 89 |
+
label="System prompt",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
)
|
| 91 |
+
temperature = gr.Slider(0.1, 1.2, value=0.7, step=0.05, label="temperature")
|
| 92 |
+
top_p = gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="top_p")
|
| 93 |
+
max_new = gr.Slider(64, 1024, value=512, step=16, label="max_new_tokens")
|
| 94 |
+
min_new = gr.Slider(0, 512, value=160, step=8, label="min_new_tokens")
|
| 95 |
+
|
| 96 |
chat = gr.ChatInterface(
|
| 97 |
fn=gradio_fn,
|
| 98 |
+
additional_inputs=[system_box, temperature, top_p, max_new, min_new],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
chatbot=gr.Chatbot(elem_classes="chatbot"),
|
|
|
|
| 100 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
if __name__ == "__main__":
|
| 103 |
demo.launch()
|