AnkitkumarMalde commited on
Commit
93b086c
·
verified ·
1 Parent(s): 7d8680a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -8
app.py CHANGED
@@ -35,16 +35,52 @@ def respond(message, history):
35
  yield response
36
 
37
  # 2. Simplified UI
38
- # Change your demo line to this:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  demo = gr.ChatInterface(
40
- fn=chat_function,
41
- theme="ocean", # Try "glass", "soft", or "monochrome"
42
- title="🚀 AI Assistant Pro",
43
- description="Developed by Kewal Dand | High-performance Chatbot",
44
- examples=["Calculate my tax", "Explain RPA", "Cricket news"],
45
- textbox=gr.Textbox(placeholder="Ask me anything...", container=False, scale=7),
 
 
 
 
 
 
 
46
  )
47
-
48
  # Custom CSS for a sleek, modern look
49
  css = """
50
  .gradio-container { background-color: #f0f2f5; }
 
35
  yield response
36
 
37
  # 2. Simplified UI
38
+ def chat_function(message, history):
39
+ """
40
+ This function takes the user input and the chat history,
41
+ sends it to the model, and yields the response.
42
+ """
43
+ messages = [{"role": "system", "content": "You are a helpful and professional AI assistant."}]
44
+
45
+ # Add previous conversation turns to the memory
46
+ for user_msg, bot_msg in history:
47
+ messages.append({"role": "user", "content": user_msg})
48
+ messages.append({"role": "assistant", "content": bot_msg})
49
+
50
+ # Add the current user message
51
+ messages.append({"role": "user", "content": message})
52
+
53
+ response = ""
54
+
55
+ # Call the model and stream the result
56
+ for message_obj in client.chat_completion(
57
+ messages,
58
+ max_tokens=512,
59
+ stream=True,
60
+ temperature=0.7,
61
+ top_p=0.95,
62
+ ):
63
+ token = message_obj.choices[0].delta.content
64
+ if token:
65
+ response += token
66
+ yield response
67
+
68
+ # 3. BUILD THE UI (Linking to the function defined above)
69
  demo = gr.ChatInterface(
70
+ fn=chat_function, # This name MUST match the function name above
71
+ title="Premium AI Chatbot",
72
+ description="A high-performance assistant hosted on Hugging Face.",
73
+ theme="soft", # Gives it a modern, rounded look
74
+ examples=["What are the benefits of RPA?", "How to optimize SIP investments?", "Explain financial planning."],
75
+ cache_examples=False,
76
+ chatbot=gr.Chatbot(
77
+ show_label=False,
78
+ show_share_button=False,
79
+ show_copy_button=True,
80
+ likeable=True,
81
+ layout="bubble"
82
+ )
83
  )
 
84
  # Custom CSS for a sleek, modern look
85
  css = """
86
  .gradio-container { background-color: #f0f2f5; }