shivrajkarewar commited on
Commit
c06d9dd
·
verified ·
1 Parent(s): 229b0f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -21
app.py CHANGED
@@ -42,35 +42,48 @@ def chat_with_groq(user_input):
42
  response = requests.post(url, headers=headers, json=body)
43
 
44
  if response.status_code == 200:
45
- base_response = response.json()['choices'][0]['message']['content']
46
-
47
- # Append popular related questions for UAE
48
- popular_questions = (
49
- "\n\n---\n"
50
- "#### 🔍 Popular related questions in the UAE:\n"
51
- "- What are the best corrosion-resistant materials for marine environments (e.g., desalination)?\n"
52
- "- Which materials are ideal for solar panel coatings and desert heat management?\n"
53
- "- What materials are used for aerospace structures in extreme climates?\n"
54
- "- Best high-strength materials for construction in the Gulf region?\n"
55
- "- What advanced materials are used in electric vehicles and batteries in the UAE?\n"
56
- )
57
-
58
- return base_response + popular_questions
59
  else:
60
  return f"Error: {response.json()}"
61
 
62
- # Build improved layout using Gradio Blocks
63
  with gr.Blocks(title="Materials Science Expert Chatbot") as demo:
64
- gr.Markdown("## 🧪 Materials Science Expert\nAsk about the best materials for a specific application.")
65
-
66
  with gr.Row():
67
- user_input = gr.Textbox(lines=2, placeholder="e.g. Best materials for high-temperature turbine blades...", label="Ask your question")
68
- submit_btn = gr.Button("Submit")
69
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  output = gr.Markdown()
71
-
72
  submit_btn.click(chat_with_groq, inputs=user_input, outputs=output)
73
 
 
 
 
 
 
 
 
 
 
 
74
  # Launch the app
75
  if __name__ == "__main__":
76
  demo.launch()
 
42
  response = requests.post(url, headers=headers, json=body)
43
 
44
  if response.status_code == 200:
45
+ return response.json()['choices'][0]['message']['content']
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  else:
47
  return f"Error: {response.json()}"
48
 
49
+ # Build Gradio interface with better layout
50
  with gr.Blocks(title="Materials Science Expert Chatbot") as demo:
51
+ gr.Markdown("## 🧪 Materials Science Expert\nAsk about the best materials for any engineering or industrial application.")
52
+
53
  with gr.Row():
54
+ with gr.Column(scale=3):
55
+ user_input = gr.Textbox(
56
+ lines=2,
57
+ placeholder="e.g. Best materials for high-temperature turbine blades...",
58
+ label="Ask your question"
59
+ )
60
+ with gr.Column(scale=1, min_width=100):
61
+ submit_btn = gr.Button("Submit", variant="primary", elem_id="orange-btn")
62
+
63
+ # Popular questions
64
+ gr.Markdown("#### 📌 Popular Materials Science related questions")
65
+ gr.Markdown("""
66
+ - What are the best corrosion-resistant materials for marine environments (e.g., desalination)?
67
+ - Which materials are ideal for solar panel coatings and desert heat management?
68
+ - What materials are used for aerospace structures in extreme climates?
69
+ - Best high-strength materials for construction in the Gulf region?
70
+ - What advanced materials are used in electric vehicles and batteries in the UAE?
71
+ """)
72
+
73
  output = gr.Markdown()
74
+
75
  submit_btn.click(chat_with_groq, inputs=user_input, outputs=output)
76
 
77
+ # CSS for orange submit button
78
+ demo.load(lambda: None, js=None, css="""
79
+ #orange-btn {
80
+ background-color: #f97316 !important;
81
+ color: white !important;
82
+ border: none;
83
+ font-weight: bold;
84
+ }
85
+ """)
86
+
87
  # Launch the app
88
  if __name__ == "__main__":
89
  demo.launch()