Habib U Rehman commited on
Commit
cc20161
·
verified ·
1 Parent(s): f57acac

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from groq import Groq
4
+
5
+ client = Groq(api_key=os.getenv("GROQ_API_KEY"))
6
+
7
+ SYSTEM_PROMPT = """
8
+ You are a knowledgeable chatbot specialized in Sindh and the Sindhi nation.
9
+ Only answer questions related to Sindh, Sindhi culture, history, language, and identity.
10
+ If the question is not related to Sindh, politely refuse.
11
+ """
12
+
13
+ def sindh_chatbot(user_input):
14
+ if not user_input.strip():
15
+ return "Please ask a question about Sindh."
16
+
17
+ try:
18
+ response = client.chat.completions.create(
19
+ model="llama-3.3-70b-versatile",
20
+ messages=[
21
+ {"role": "system", "content": SYSTEM_PROMPT},
22
+ {"role": "user", "content": user_input},
23
+ ],
24
+ temperature=0.6,
25
+ max_tokens=400,
26
+ )
27
+ return response.choices[0].message.content
28
+
29
+ except Exception:
30
+ return "⚠️ Error: GROQ API key missing or service unavailable."
31
+
32
+ interface = gr.Interface(
33
+ fn=sindh_chatbot,
34
+ inputs=gr.Textbox(lines=3, placeholder="Ask about Sindh..."),
35
+ outputs="text",
36
+ title="Sindh & Sindhi Nation Chatbot"
37
+ )
38
+
39
+ if __name__ == "__main__":
40
+ interface.launch()