shibly100 commited on
Commit
1d2f436
·
verified ·
1 Parent(s): 7a4012e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -1,26 +1,29 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load your fine-tuned Corporate Leadership model from Hugging Face
5
  generator = pipeline("text-generation", model="shibly100/gpt2_corporate_leadership")
6
 
7
- # Define chatbot function
8
- def chat_with_ai(prompt):
9
- response = generator(prompt, max_length=200, do_sample=True)
10
- return response[0]["generated_text"]
 
 
 
 
 
 
11
 
12
- # Create the Gradio Chatbot Interface
13
- demo = gr.Interface(
14
- fn=chat_with_ai,
15
- inputs=gr.Textbox(lines=3, placeholder="Ask anything about corporate leadership..."),
16
- outputs="text",
17
- title="SPARKY Corporate Leadership AI",
18
- description="Ask anything about corporate leadership and get AI-powered insights!",
19
- allow_flagging="never",
20
  )
21
 
22
  # Launch the chatbot
23
- demo.launch()
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