Shriti09 commited on
Commit
e174a9c
·
verified ·
1 Parent(s): 5044361

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -6,7 +6,7 @@ import gradio as gr
6
  # Use GPU if available
7
  device = "cuda" if torch.cuda.is_available() else "cpu"
8
 
9
- # Base model and adapter paths (updated for Hugging Face repo)
10
  base_model_name = "microsoft/phi-2" # Pull from HF Hub directly
11
  adapter_path = "Shriti09/Microsoft-Phi-QLora" # Update with your Hugging Face repo path
12
 
@@ -30,7 +30,7 @@ print("✅ Model ready for inference!")
30
 
31
  # Chat function with history
32
  def chat_fn(message, history):
33
- # Combine conversation history into one prompt
34
  full_prompt = ""
35
  for user_msg, bot_msg in history:
36
  full_prompt += f"User: {user_msg}\nAI: {bot_msg}\n"
@@ -53,8 +53,10 @@ def chat_fn(message, history):
53
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
54
  response = response.split("AI:")[-1].strip()
55
 
56
- # Append to history
57
- history.append((message, response))
 
 
58
  return history, history
59
 
60
  # Gradio UI
@@ -72,5 +74,5 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
72
  clear.click(lambda: [], None, chatbot)
73
  clear.click(lambda: [], None, state)
74
 
75
- # Run the app without the 'concurrency_count' argument
76
- demo.queue().launch()
 
6
  # Use GPU if available
7
  device = "cuda" if torch.cuda.is_available() else "cpu"
8
 
9
+ # Base model and adapter paths
10
  base_model_name = "microsoft/phi-2" # Pull from HF Hub directly
11
  adapter_path = "Shriti09/Microsoft-Phi-QLora" # Update with your Hugging Face repo path
12
 
 
30
 
31
  # Chat function with history
32
  def chat_fn(message, history):
33
+ # Convert history to the required format for gr.Chatbot (list of dictionaries with role and content)
34
  full_prompt = ""
35
  for user_msg, bot_msg in history:
36
  full_prompt += f"User: {user_msg}\nAI: {bot_msg}\n"
 
53
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
54
  response = response.split("AI:")[-1].strip()
55
 
56
+ # Append to history in the correct format for gr.Chatbot (list of dictionaries)
57
+ history.append({"role": "user", "content": message})
58
+ history.append({"role": "assistant", "content": response})
59
+
60
  return history, history
61
 
62
  # Gradio UI
 
74
  clear.click(lambda: [], None, chatbot)
75
  clear.click(lambda: [], None, state)
76
 
77
+ # Run the app without the 'concurrency_count' argument and share the app publicly
78
+ demo.queue().launch(share=True)