Snapspark commited on
Commit
b768fad
·
verified ·
1 Parent(s): 352c084

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ # This uses a free Hugging Face API model (no credit card needed)
5
+ API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
6
+ HEADERS = {"Authorization": "Bearer YOUR_HF_TOKEN"} # You'll get this in step 2 below
7
+
8
+ def chat_with_ai(prompt, history):
9
+ if not prompt.strip():
10
+ return "", history
11
+
12
+ # Prepare the prompt for the model
13
+ full_prompt = f"<s>[INST] You are a helpful AI project assistant. Answer clearly and concisely. {prompt} [/INST]"
14
+
15
+ try:
16
+ response = requests.post(API_URL, headers=HEADERS, json={"inputs": full_prompt})
17
+ result = response.json()
18
+ reply = result[0]["generated_text"].split("[/INST]")[-1].strip()
19
+ except Exception as e:
20
+ reply = f"⚠️ Error: {str(e)}. Please check your token or internet connection."
21
+
22
+ history.append((prompt, reply))
23
+ return "", history
24
+
25
+ # Build the UI
26
+ with gr.Blocks(theme="soft") as demo:
27
+ gr.Markdown("# 🤖 Hermus AI Project Assistant")
28
+ gr.Markdown("Ask me to write code, plan projects, or debug anything.")
29
+
30
+ chatbot = gr.Chatbot(height=400)
31
+ msg = gr.Textbox(label="Your message", placeholder="Type your project question here...")
32
+ clear = gr.Button("Clear chat")
33
+
34
+ msg.submit(chat_with_ai, [msg, chatbot], [msg, chatbot])
35
+ clear.click(lambda: None, None, chatbot, queue=False)
36
+
37
+ demo.launch()