shibly100 commited on
Commit
243c45c
·
verified ·
1 Parent(s): 1d2f436

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -29
app.py CHANGED
@@ -1,29 +1,19 @@
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
-
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the fine-tuned model
5
+ generator = pipeline("text-generation", model="shibly100/gpt2_corporate_leadership")
6
+
7
+ # Function to generate responses
8
+ def chat_with_ai(prompt, history=[]):
9
+ response = generator(prompt, max_length=200, do_sample=True, top_p=0.95, top_k=50, temperature=0.7)
10
+ return response[0]["generated_text"]
11
+
12
+ # Fast and simple chat interface
13
+ with gr.Blocks() as demo:
14
+ gr.Markdown("# SPARKY Corporate Leadership AI")
15
+ gr.Markdown("Ask anything about corporate leadership and get AI-powered responses!")
16
+
17
+ chatbot = gr.ChatInterface(chat_with_ai)
18
+
19
+ demo.launch()