ravindravala commited on
Commit
efc2981
·
1 Parent(s): 61dbb0e

added simple chatbot

Browse files
Files changed (3) hide show
  1. .gitignore +6 -0
  2. app.py +37 -0
  3. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ venv/
2
+ myenv/
3
+ __pycache__/
4
+ *.pyc
5
+ .env
6
+ .DS_Store
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from dotenv import load_dotenv
4
+ from huggingface_hub import InferenceClient
5
+
6
+ # Load env
7
+ load_dotenv()
8
+ HF_TOKEN = os.getenv("HF_TOKEN")
9
+ print("HF_TOKEN loaded:", bool(HF_TOKEN))
10
+
11
+ # Free HF model (works on free tier)
12
+ client = InferenceClient(
13
+ model="meta-llama/Llama-3.2-1B-Instruct",
14
+ token=HF_TOKEN
15
+ )
16
+
17
+ def chat(message, history):
18
+ messages = [
19
+ {"role": "system", "content": "You are a helpful AI assistant."},
20
+ {"role": "user", "content": message}
21
+ ]
22
+
23
+ response = client.chat.completions.create(
24
+ messages=messages,
25
+ max_tokens=300,
26
+ temperature=0.7,
27
+ )
28
+
29
+ return response.choices[0].message.content
30
+
31
+ demo = gr.ChatInterface(
32
+ fn=chat,
33
+ title="🤖 Simple AI Chatbot",
34
+ description="Gradio + Hugging Face (free model)"
35
+ )
36
+
37
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ huggingface_hub
3
+ python-dotenv