JDhruv14 commited on
Commit
a2b7239
·
verified ·
1 Parent(s): b934f15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -18
app.py CHANGED
@@ -73,31 +73,67 @@ 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
- # 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()
 
 
73
  reply = tokenizer.batch_decode(new_tokens, skip_special_tokens=True)[0].strip()
74
  return reply
75
 
76
+ @spaces.GPU()
77
+ def gradio_fn(message, history):
78
+ response = infer_text(history + [(message, None)])
79
+ return response
80
 
81
+ with gr.Blocks(css="""
82
+ .gradio-container {
83
+ max-width: 600px;
84
+ margin: auto;
85
+ padding: 20px;
86
+ font-family: sans-serif;
87
+ position: relative;
88
+ }
89
+ .chatbot {
90
+ height: 500px !important;
91
+ overflow-y: auto;
92
+ }
93
+ .corner {
94
+ position: fixed;
95
+ bottom: 2px;
96
+ z-index: 9999;
97
+ pointer-events: none;
98
+ }
99
+ #left { left: 2px; }
100
+ #right { right: 2px; }
101
+ .corner img {
102
+ height: 500px; /* fixed height */
103
+ width: auto; /* auto to keep aspect ratio */
104
+ }
105
+
106
+ """) as demo:
107
  gr.Markdown(
108
+ """
109
+ <div style='text-align: center; padding: 10px;'>
110
+ <h1 style='font-size: 2.2em; margin-bottom: 0.2em;'>🤖 <span style='color: #4F46E5;'>kRISHNA.ai</span></h1>
111
+ <p style='font-size: 1.1em; color: #555;'>5000-Years of Ancient WISDOM with Modern AI ✨</p>
112
+ </div>
113
+ """,
114
+ elem_id="header"
115
  )
 
 
 
 
 
 
 
 
 
 
116
  chat = gr.ChatInterface(
117
  fn=gradio_fn,
118
+ examples=[
119
+ "Hello!",
120
+ "How can I overcome fear of failure?",
121
+ "How do I forgive someone who hurt me deeply?",
122
+ "What can I do to stop overthinking?"
123
+ ],
124
  chatbot=gr.Chatbot(elem_classes="chatbot"),
125
+ theme="compact",
126
  )
127
+ gr.HTML(f"""
128
+ <div id="left" class="corner">
129
+ <img src="" alt="Arjun">
130
+ </div>
131
+ <div id="right" class="corner">
132
+ <img src="" alt="Krishna">
133
+ </div>
134
+ """)
135
+
136
 
137
  if __name__ == "__main__":
138
  demo.launch()
139
+