ch103 commited on
Commit
91912d4
·
1 Parent(s): aec290b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -1,31 +1,35 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Initialize your model here. Replace 'your_model_name' with the actual model name
5
- chat_model = pipeline('text-generation', model='ch103/llama-2-7b-miniguanaco')
 
 
6
 
7
- def chat_with_cthulhu(user_message):
8
- formatted_input = f"<s>[INST] {user_message} [/INST]"
9
- response = chat_model(formatted_input, max_length=512)
10
- response_text = response[0]['generated_text']
11
 
12
- # Extracting the AI response part
13
- # Assuming the response follows the format: <s>[INST] User Message [/INST] AI Response </s>
 
 
 
 
14
  response_parts = response_text.split("[/INST]")
15
  if len(response_parts) > 1:
16
- ai_response = response_parts[1].replace("</s>", "").strip()
17
  else:
18
  ai_response = "Sorry, I couldn't process that message."
19
 
20
  return ai_response
21
 
22
  gradio_app = gr.Interface(
23
- fn=chat_with_cthulhu,
24
- inputs=gr.Textbox(lines=2, placeholder="Type your message to the Keeper..."),
25
  outputs=gr.Textbox(),
26
- title="Call of Cthulhu Keeper Chatbot",
27
- description="Chat with the Keeper from Call of Cthulhu. Ask questions or seek guidance."
28
  )
29
 
30
  if __name__ == "__main__":
31
  gradio_app.launch()
 
 
1
  import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
3
 
4
+ # Replace 'your_model_name' with the actual name or path of your model
5
+ model_name = 'your_model_name'
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
 
9
+ pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200)
 
 
 
10
 
11
+ def generate_response(user_input):
12
+ formatted_input = f"<s>[INST] {user_input} [/INST]"
13
+ result = pipe(formatted_input)
14
+ response_text = result[0]['generated_text']
15
+
16
+ # Extracting the AI response part, assuming it follows a specific format after [/INST]
17
  response_parts = response_text.split("[/INST]")
18
  if len(response_parts) > 1:
19
+ ai_response = response_parts[1].split("</s>")[0].strip() # Assuming the response ends with </s>
20
  else:
21
  ai_response = "Sorry, I couldn't process that message."
22
 
23
  return ai_response
24
 
25
  gradio_app = gr.Interface(
26
+ fn=generate_response,
27
+ inputs=gr.Textbox(lines=2, placeholder="Enter your message here..."),
28
  outputs=gr.Textbox(),
29
+ title="Call of Cthulhu Chatbot",
30
+ description="Interact with the Call of Cthulhu Keeper. Type your actions or questions."
31
  )
32
 
33
  if __name__ == "__main__":
34
  gradio_app.launch()
35
+