rahmanmaqbool286 commited on
Commit
8748fe2
·
verified ·
1 Parent(s): ffb436f

requirements.txt

Browse files

gradio
transformers
torch

Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load text generation model
5
+ chatbot = pipeline(
6
+ "text-generation",
7
+ model="distilgpt2"
8
+ )
9
+
10
+ def human_chat(user_input):
11
+ prompt = (
12
+ "You are a friendly, polite, and helpful human assistant. "
13
+ "Answer clearly and naturally.\n\n"
14
+ f"User: {user_input}\nAssistant:"
15
+ )
16
+
17
+ response = chatbot(
18
+ prompt,
19
+ max_length=150,
20
+ do_sample=True,
21
+ temperature=0.7,
22
+ top_p=0.9
23
+ )
24
+
25
+ reply = response[0]["generated_text"]
26
+ reply = reply.split("Assistant:")[-1].strip()
27
+
28
+ return reply
29
+
30
+ # Gradio UI
31
+ iface = gr.Interface(
32
+ fn=human_chat,
33
+ inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
34
+ outputs="text",
35
+ title="Human-Like AI Chatbot 🤖",
36
+ description="This chatbot responds in friendly, human-style language."
37
+ )
38
+
39
+ iface.launch()