Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load
|
5 |
generator = pipeline("text-generation", model="shibly100/gpt2_corporate_leadership")
|
6 |
|
7 |
-
# Define
|
8 |
-
def chat_with_ai(
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
# Create
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
description="Ask anything about corporate leadership and get AI-powered insights!",
|
19 |
-
allow_flagging="never",
|
20 |
)
|
21 |
|
22 |
# Launch the chatbot
|
23 |
-
|
24 |
-
|
25 |
|
26 |
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load the fine-tuned Corporate Leadership model from Hugging Face
|
5 |
generator = pipeline("text-generation", model="shibly100/gpt2_corporate_leadership")
|
6 |
|
7 |
+
# Define the chat function that remembers conversation history
|
8 |
+
def chat_with_ai(history, message):
|
9 |
+
full_prompt = " ".join([turn[0] + " " + turn[1] for turn in history] + [message])
|
10 |
+
response = generator(full_prompt, max_length=300, do_sample=True, temperature=0.7)
|
11 |
+
reply = response[0]["generated_text"]
|
12 |
+
|
13 |
+
# Ensure only new AI-generated response is returned
|
14 |
+
reply = reply[len(full_prompt):].strip()
|
15 |
+
history.append((message, reply))
|
16 |
+
return history, ""
|
17 |
|
18 |
+
# Create Chatbot Interface
|
19 |
+
chatbot = gr.ChatInterface(
|
20 |
+
chat_with_ai,
|
21 |
+
title="🗣️ SPARKY Corporate Leadership AI",
|
22 |
+
description="🤖 Ask anything about corporate leadership and get AI-powered responses! Your conversation history is remembered.",
|
23 |
+
theme="soft", # This gives it a sleek, modern look like ChatGPT
|
|
|
|
|
24 |
)
|
25 |
|
26 |
# Launch the chatbot
|
27 |
+
chatbot.launch()
|
|
|
28 |
|
29 |
|