aimanathar commited on
Commit
8796b9c
·
verified ·
1 Parent(s): 4372ad4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -99
app.py CHANGED
@@ -1,79 +1,11 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
3
 
4
- # Hardcoded Token & Model
5
- HF_TOKEN = "hf_your_token_here" # apna HF token paste karein
6
- MODEL_NAME = "openai/gpt-oss-20b"
7
-
8
- # 🔒 Hardcoded Practical Lists
9
- hardcoded_answers = {
10
- "chemistry class 9 practicals": """🔬 Chemistry Class IX (Practical Index)
11
-
12
- - To separate the given mixture by physical method
13
- - To determine the melting point of naphthalene
14
- - To determine the boiling point of acetone
15
- - To separate naphthalene from mixture of naphthalene and sand (sublimation)
16
- - To separate alcohol and water by distillation
17
- - To demonstrate that chemical reaction releases energy in the form of heat
18
- - To prepare 100 mL of 0.1M sodium hydroxide solution
19
- - To prepare 250 mL of 0.1M hydrochloric acid solution
20
- - To prepare 100 mL of 0.1M sodium carbonate solution
21
- - To prepare 100 mL of 0.1M NaOH by dilution of given solution
22
- - To prepare pure copper sulphate crystals from impure sample
23
- - To demonstrate miscible and immiscible liquids
24
- - To demonstrate effect of temperature on solubility
25
- - To demonstrate electrical conductivity of different solutions
26
- - To demonstrate formation of a binary compound""",
27
-
28
- "chemistry class 10 practicals": """🔬 Chemistry Class X (Practical Index)
29
-
30
- - Identify sodium, calcium, strontium, barium, copper and potassium ions by flame test
31
- - Standardize the given HCl solution volumetrically
32
- - Determine exact molarity of Na₂CO₃ solution volumetrically
33
- - Demonstrate that some natural substances are weak acids
34
- - Classify substances as acidic, basic, or neutral
35
- - Demonstrate decomposition of sugar into elements/compounds""",
36
-
37
- "physics class 9 practicals": """⚙ Physics Class IX (Practical Index)
38
-
39
- - To measure area of cross-section of a cylinder using vernier callipers
40
- - To measure volume of a solid cylinder using vernier callipers
41
- - To study motion of a ball rolling down an inclined plane (s vs t² graph)
42
- - To determine acceleration due to gravity (g) by free fall method
43
- - To find limiting friction by roller method
44
- - To find resultant of two forces acting at a point by graphical method
45
- - To verify principle of moments using a beam balance
46
- - To study variation of time period of a pendulum with length and calculate g
47
- - To determine density of a solid heavier than water using Archimedes principle
48
- - To study temperature vs time graph (ice → water → steam)""",
49
-
50
- "physics class 10 practicals": """⚙ Physics Class X (Practical Index)
51
-
52
- - To verify the law of reflection of light
53
- - To find refractive index of water using a concave mirror
54
- - To determine critical angle of glass using semicircular slab/prism
55
- - To trace path of a ray of light through a glass prism and measure deviation
56
- - To find focal length of convex lens (parallel ray/parallax method)
57
- - To set up an astronomical telescope
58
- - To set up a microscope
59
- - To verify Ohm’s law using wire as a conductor
60
- - To study resistors in series circuit
61
- - To study resistors in parallel circuit
62
- - To determine resistance of a galvanometer by half-deflection method
63
- - To trace magnetic field using a bar magnet"""
64
- }
65
-
66
 
67
  def respond(message, history: list[dict[str, str]]):
68
- # Pehle check karein hardcoded answers
69
- lower_msg = message.lower()
70
- for key, answer in hardcoded_answers.items():
71
- if key in lower_msg:
72
- yield answer
73
- return # yahan se return ho jayega, model call nahi hoga
74
-
75
- # ✅ Agar hardcoded nahi mila toh model se response lo
76
- client = InferenceClient(token=HF_TOKEN, model=MODEL_NAME)
77
 
78
  messages = [{"role": "system", "content": "You are a friendly chatbot."}]
79
  messages.extend(history)
@@ -92,34 +24,82 @@ def respond(message, history: list[dict[str, str]]):
92
  yield response
93
 
94
 
95
- # 💜 CSS aur UI wahi rakha jo aapke code me hai
96
- custom_css = """ ... (same CSS as before) ... """
97
-
98
- with gr.Blocks(css=custom_css) as demo:
99
- with gr.Column():
100
- gr.HTML("<div class='top-bar'>💬 Virtual Chatbot</div>")
101
- chatbot = gr.Chatbot(elem_classes="chatbot", bubble_full_width=False, show_copy_button=False)
102
- with gr.Row(elem_classes="input-area"):
103
- msg = gr.Textbox(placeholder="Type your message...", lines=1)
104
- send_btn = gr.Button("➤")
105
-
106
- def user_submit(user_message, chat_history):
107
- return "", chat_history + [(user_message, None)]
108
-
109
- def bot_response(chat_history):
110
- user_message = chat_history[-1][0]
111
- response = ""
112
- for partial in respond(user_message, [{"role": "user", "content": h[0]} for h in chat_history[:-1]]):
113
- response = partial
114
- chat_history[-1] = (chat_history[-1][0], response)
115
- return chat_history
116
-
117
- msg.submit(user_submit, [msg, chatbot], [msg, chatbot]).then(
118
- bot_response, chatbot, chatbot
119
- )
120
- send_btn.click(user_submit, [msg, chatbot], [msg, chatbot]).then(
121
- bot_response, chatbot, chatbot
122
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
  if __name__ == "__main__":
125
  demo.launch(share=True)
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ import os
4
 
5
+ HF_TOKEN = os.getenv("HF_TOKEN")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  def respond(message, history: list[dict[str, str]]):
8
+ client = InferenceClient(token=HF_TOKEN, model="openai/gpt-oss-20b")
 
 
 
 
 
 
 
 
9
 
10
  messages = [{"role": "system", "content": "You are a friendly chatbot."}]
11
  messages.extend(history)
 
24
  yield response
25
 
26
 
27
+ # Improved Purple + White/Grey Theme CSS + Footer Hide
28
+ custom_css = """
29
+ .gradio-container {
30
+ background: linear-gradient(to bottom right, #7E498B, #f5f5f5);
31
+ font-family: 'Segoe UI', sans-serif;
32
+ height: 100vh;
33
+ padding: 20px;
34
+ }
35
+
36
+ /* Chat box styling */
37
+ .svelte-1ipelgc, .svelte-1f354aw {
38
+ border-radius: 16px !important;
39
+ background: white !important;
40
+ padding: 12px !important;
41
+ box-shadow: 0px 4px 20px rgba(0,0,0,0.08) !important;
42
+ }
43
+
44
+ /* User bubble */
45
+ .user.svelte-1ipelgc {
46
+ background: linear-gradient(135deg, #7E498B, #9b59b6) !important;
47
+ color: white !important;
48
+ border-radius: 18px 18px 0 18px !important;
49
+ padding: 10px 14px !important;
50
+ max-width: 80% !important;
51
+ animation: fadeIn 0.3s ease-in;
52
+ }
53
+
54
+ /* Bot bubble */
55
+ .bot.svelte-1ipelgc {
56
+ background: #f1f1f1 !important;
57
+ color: #333 !important;
58
+ border-radius: 18px 18px 18px 0 !important;
59
+ padding: 10px 14px !important;
60
+ max-width: 80% !important;
61
+ box-shadow: 0px 2px 6px rgba(0,0,0,0.05) !important;
62
+ animation: fadeIn 0.3s ease-in;
63
+ }
64
+
65
+ /* Input box */
66
+ textarea {
67
+ border-radius: 25px !important;
68
+ padding: 12px 16px !important;
69
+ border: 1px solid #ddd !important;
70
+ outline: none !important;
71
+ font-size: 15px !important;
72
+ resize: none !important;
73
+ }
74
+
75
+ /* Send button */
76
+ button {
77
+ border-radius: 25px !important;
78
+ background: linear-gradient(135deg, #7E498B, #9b59b6) !important;
79
+ color: white !important;
80
+ font-weight: bold !important;
81
+ transition: 0.3s;
82
+ }
83
+
84
+ button:hover {
85
+ background: #632f73 !important;
86
+ }
87
+
88
+ /* Animations */
89
+ @keyframes fadeIn {
90
+ from {opacity: 0; transform: translateY(10px);}
91
+ to {opacity: 1; transform: translateY(0);}
92
+ }
93
+
94
+ /* Hide Gradio Footer (API, Logo, Settings) */
95
+ footer, .svelte-1yycg3h, .builder-bar, .wrap.svelte-1ipelgc {
96
+ display: none !important;
97
+ visibility: hidden !important;
98
+ }
99
+ """
100
+
101
+ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
102
+ gr.ChatInterface(respond, type="messages")
103
 
104
  if __name__ == "__main__":
105
  demo.launch(share=True)