Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,47 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# Install the Hugging Face CLI
|
| 3 |
+
powershell -ExecutionPolicy ByPass -c "irm https://hf.co/cli/install.ps1 | iex"
|
| 4 |
+
|
| 5 |
+
# (optional) Login with your Hugging Face credentials
|
| 6 |
+
hf auth login
|
| 7 |
+
|
| 8 |
+
# Push your model files
|
| 9 |
+
hf upload RAAZIM/RT-AI .
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
import gradio as gr
|
| 16 |
+
from transformers import pipeline
|
| 17 |
+
|
| 18 |
+
# 1. Load the GPT-Neo model (free to use)
|
| 19 |
+
generator = pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")
|
| 20 |
+
|
| 21 |
+
# 2. Create multi-turn chat memory
|
| 22 |
+
history = []
|
| 23 |
+
|
| 24 |
+
def chat(input_text):
|
| 25 |
+
global history
|
| 26 |
+
# Add user input to history
|
| 27 |
+
history.append(f"User: {input_text}")
|
| 28 |
+
# Prepare prompt with conversation history
|
| 29 |
+
prompt = "\n".join(history) + "\nAI:"
|
| 30 |
+
# Generate response
|
| 31 |
+
response = generator(prompt, max_length=200, do_sample=True, temperature=0.7)
|
| 32 |
+
ai_text = response[0]["generated_text"]
|
| 33 |
+
# Add AI response to history
|
| 34 |
+
history.append(f"AI: {ai_text}")
|
| 35 |
+
return ai_text
|
| 36 |
+
|
| 37 |
+
# 3. Gradio interface
|
| 38 |
+
iface = gr.Interface(
|
| 39 |
+
fn=chat,
|
| 40 |
+
inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
|
| 41 |
+
outputs="text",
|
| 42 |
+
title="AltisBot", # <-- Your chatbot name here
|
| 43 |
+
description="Your free AI assistant chatbot"
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# 4. Launch the interface
|
| 47 |
+
iface.launch()
|