Hermus-ai / app.py
Snapspark's picture
Update app.py
ba9f85e verified
Raw
History Blame Contribute Delete
1.42 kB
import gradio as gr
import requests
# This uses a free Hugging Face API model (no credit card needed)
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
HEADERS = {"Authorization": "Bearer YOUR_HF_TOKEN"} # You'll get this in step 2 below
def chat_with_ai(prompt, history):
if not prompt.strip():
return "", history
# Prepare the prompt for the model
full_prompt = f"<s>[INST] You are a helpful AI project assistant. Answer clearly and concisely. {prompt} [/INST]"
try:
response = requests.post(API_URL, headers=HEADERS, json={"inputs": full_prompt})
result = response.json()
reply = result[0]["generated_text"].split("[/INST]")[-1].strip()
except Exception as e:
reply = f"⚠️ Error: {str(e)}. Please check your token or internet connection."
history.append((prompt, reply))
return "", history
# Build the UI
with gr.Blocks(theme="soft") as demo:
gr.Markdown("# 🤖 Hermus AI Project Assistant")
gr.Markdown("Ask me to write code, plan projects, or debug anything.")
chatbot = gr.Chatbot(height=400)
msg = gr.Textbox(label="Your message", placeholder="Type your project question here...")
clear = gr.Button("Clear chat")
msg.submit(chat_with_ai, [msg, chatbot], [msg, chatbot])
clear.click(lambda: None, None, chatbot, queue=False)
demo.launch()