RAAZIM commited on
Commit
574add2
·
verified ·
1 Parent(s): c4c8c8b

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # 1. Load the GPT-Neo model (free to use)
5
+ generator = pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")
6
+
7
+ # 2. Create multi-turn chat memory
8
+ history = []
9
+
10
+ def chat(input_text):
11
+ global history
12
+ # Add user input to history
13
+ history.append(f"User: {input_text}")
14
+ # Prepare prompt with conversation history
15
+ prompt = "\n".join(history) + "\nAI:"
16
+ # Generate response
17
+ response = generator(prompt, max_length=200, do_sample=True, temperature=0.7)
18
+ ai_text = response[0]["generated_text"]
19
+ # Add AI response to history
20
+ history.append(f"AI: {ai_text}")
21
+ return ai_text
22
+
23
+ # 3. Gradio interface
24
+ iface = gr.Interface(
25
+ fn=chat,
26
+ inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
27
+ outputs="text",
28
+ title="AltisBot", # <-- Your chatbot name here
29
+ description="Your free AI assistant chatbot"
30
+ )
31
+
32
+ # 4. Launch the interface
33
+ iface.launch()