nidheesh1994 commited on
Commit
fb7b139
Β·
verified Β·
1 Parent(s): 821bf70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -26
app.py CHANGED
@@ -2,35 +2,57 @@ import os
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
5
- HF_TOKEN = os.getenv("HF_TOKEN")
6
 
7
- client = InferenceClient(
8
- model="meta-llama/Llama-3.2-11B-Vision-Instruct",
9
- token=HF_TOKEN,
10
- )
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- def describe_image(image_url, user_message):
13
- response = client.chat_completion(
14
- messages=[
15
- {
16
- "role": "user",
17
- "content": [
18
- {"type": "text", "text": user_message},
19
- {"type": "image_url", "image_url": {"url": image_url}},
20
- ],
21
- }
22
- ],
 
 
 
 
 
 
 
 
 
 
 
23
  )
24
- return response["choices"][0]["message"]["content"]
25
-
26
- demo = gr.Interface(
27
- fn=describe_image,
28
- inputs=[
29
- gr.Textbox(label="Image URL"),
30
- gr.Textbox(label="Prompt"),
31
- ],
32
- outputs=gr.Textbox(label="Response"),
33
- title="LLaMA 3 Vision Instruct",
34
  )
35
 
36
  if __name__ == "__main__":
 
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
5
+ HF_TOKEN = os.getenv("HF_TOKEN") # add in Space > Settings > Secrets
6
 
7
+ MODEL_ID = "HuggingFaceTB/SmolLM3-3B"
8
+
9
+ # Create the InferenceClient (no provider arg needed)
10
+ client = InferenceClient(model=MODEL_ID, token=HF_TOKEN)
11
+
12
+ # ─── System prompt ────────────────────────────────────────────
13
+ SYSTEM_PROMPT = """
14
+ You are Prometheous, a highly knowledgeable and friendly AI assistant developed by Nidheesh Jagadeesan.
15
+ You always begin with: "Hi, I am Prometheous. Assistant of Nidheesh J. What do you want to know about him?"
16
+
17
+ Here is Nidheesh’s profile:
18
+ - Senior Full Stack Developer & AI Researcher (8+ years)
19
+ - MSc Artificial Intelligence & Robotics, University of Hertfordshire
20
+ - Expert in Laravel, Symfony, Vue.js, React.js, Node.js, Shopware 6, Docker, Redis, GCP, AI/ML, HPC
21
+ - Projects: GA + RL autonomous car simulation, AI stock trader, AI-powered Shopware plugin
22
+ - Certifications: Microsoft Azure AI Fundamentals (2024)
23
 
24
+ Always respond confidently, e.g.
25
+ "As Nidheesh’s assistant, I can tell you that …"
26
+ """
27
+
28
+ # ─── Build chat messages list for OpenAI format ───────────────
29
+ def build_messages(user_msg: str, history: list[tuple[str, str]]) -> list[dict]:
30
+ messages = [{"role": "system", "content": SYSTEM_PROMPT}]
31
+ for user, bot in history:
32
+ messages.append({"role": "user", "content": user})
33
+ messages.append({"role": "assistant", "content": bot})
34
+ messages.append({"role": "user", "content": user_msg})
35
+ return messages
36
+
37
+ # ─── Gradio response handler ──────────────────────────────────
38
+ def respond(message, history, _ignored):
39
+ messages = build_messages(message, history)
40
+ completion = client.chat.completions.create(
41
+ model=MODEL_ID,
42
+ messages=messages,
43
+ max_tokens=512,
44
+ temperature=0.7,
45
+ top_p=0.95,
46
  )
47
+ reply = completion.choices[0].message.content.strip()
48
+ return reply
49
+
50
+ # ─── Gradio ChatInterface ─────────────────────────────────────
51
+ demo = gr.ChatInterface(
52
+ fn=respond,
53
+ additional_inputs=[gr.Textbox(value=SYSTEM_PROMPT, label="System Prompt", interactive=False)],
54
+ title="Prometheous – Your AI Assistant (SmolLM3-3B)",
55
+ description="Ask anything about Nidheesh Jagadeesan.",
 
56
  )
57
 
58
  if __name__ == "__main__":