isana25 commited on
Commit
3520c16
·
verified ·
1 Parent(s): 672c0c4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ # Replace with your actual Groq API Key
5
+ GROQ_API_KEY = "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"
6
+
7
+ # Groq's LLaMA2 endpoint
8
+ GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions"
9
+
10
+ # System prompt to define bot behavior
11
+ system_prompt = (
12
+ "You are a Construction Material Advisor Bot. Your job is to recommend the best construction materials "
13
+ "for civil engineering projects based on environmental conditions, budget, load requirements, and durability. "
14
+ "Be concise, informative, and explain pros and cons of materials."
15
+ )
16
+
17
+ # Function to get response from Groq API
18
+ def get_material_advice(user_query):
19
+ headers = {
20
+ "Authorization": f"Bearer {GROQ_API_KEY}",
21
+ "Content-Type": "application/json"
22
+ }
23
+
24
+ payload = {
25
+ "model": "llama2-70b-4096", # You can use llama2-7b if available
26
+ "messages": [
27
+ {"role": "system", "content": system_prompt},
28
+ {"role": "user", "content": user_query}
29
+ ],
30
+ "temperature": 0.7,
31
+ "max_tokens": 500
32
+ }
33
+
34
+ try:
35
+ response = requests.post(GROQ_API_URL, headers=headers, json=payload)
36
+ response.raise_for_status()
37
+ data = response.json()
38
+ return data["choices"][0]["message"]["content"].strip()
39
+ except Exception as e:
40
+ return f"Error: {str(e)}"
41
+
42
+ # Gradio interface
43
+ demo = gr.Interface(
44
+ fn=get_material_advice,
45
+ inputs=gr.Textbox(lines=3, placeholder="Ask about construction materials..."),
46
+ outputs="text",
47
+ title="🧱 Construction Material Advisor Bot",
48
+ description="Ask questions like 'What is the best material for a coastal bridge?' or 'Suggest budget-friendly wall material for cold regions.'"
49
+ )
50
+
51
+ # Launch app
52
+ demo.launch()