imenayadi commited on
Commit
4b04211
·
1 Parent(s): 681c007

remove llama model

Browse files
Files changed (1) hide show
  1. app.py +53 -54
app.py CHANGED
@@ -73,54 +73,53 @@ model_basename = "llama-2-13b-chat.ggmlv3.q5_1.bin" # The model is in bin forma
73
 
74
  # Download the model file
75
  print('downloading llama model...')
76
- model_path_llama = hf_hub_download(repo_id=model_name_or_path, filename=model_basename, force_download=True, local_dir="./llama-model")
77
  print('finished download...')
78
  # Initialize the Llama model with appropriate settings for GPU
79
- lcpp_llm = Llama(
80
- model_path=model_path_llama,
81
- n_batch=512, # Batch size for processing; adjust as per your VRAM capacity
82
- )
83
-
84
- def generate_email_response(email_prompt):
85
- # Check input received by the function
86
- print("Received prompt:", email_prompt)
87
-
88
- # Determine if the input is a shorthand command or an actual email
89
- if 'email to' in email_prompt.lower():
90
- # Assume it's a shorthand command, format appropriately
91
- formatted_prompt = f'''
92
- Email received: "{email_prompt}"
93
- Respond to this email, ensuring a professional tone, providing a concise update, and addressing any potential concerns the sender might have.
94
- Response:
95
- '''
96
- else:
97
- # Assume it's direct email content
98
- formatted_prompt = f'''
99
- Email received: "{email_prompt}"
100
- Respond to this email, ensuring a professional tone, providing a concise update, and addressing any potential concerns the sender might have.
101
- Response:
102
- '''
103
-
104
- # Generate response using Llama-2 model
105
- try:
106
- response = lcpp_llm(
107
- prompt=formatted_prompt,
108
- max_tokens=256,
109
- temperature=0.5,
110
- top_p=0.95,
111
- repeat_penalty=1.2,
112
- top_k=150,
113
- echo=True
114
- )
115
- generated_response = response["choices"][0]["text"]
116
- # Remove the input part from the output if it is included
117
- if formatted_prompt in generated_response:
118
- generated_response = generated_response.replace(formatted_prompt, '').strip()
119
- print("Generated response:", generated_response)
120
- return generated_response
121
- except Exception as e:
122
- print("Error in response generation:", str(e))
123
- return "Failed to generate response, please check the console for errors."
124
 
125
  def classify_sentiment(text):
126
  # Encode the text using the tokenizer
@@ -215,15 +214,15 @@ iface_ner = gr.Interface(
215
  title="NER Analysis",
216
  description="Performs Named Entity Recognition using spaCy and Transformer models."
217
  )
218
- iface_response = gr.Interface(
219
- fn=generate_email_response,
220
- inputs=gr.Textbox(lines=10, placeholder="Enter the email prompt..."),
221
- outputs=gr.Textbox(label="Generated Email Response"),
222
- title="Email Response Generator",
223
- description="Generate email responses using Llama-2 model."
224
- )
225
 
226
  # Using tabs to organize the interfaces
227
- tabs = gr.TabbedInterface([iface_category, iface_sentiment,iface_summary,iface_ner,iface_response], ["Category", "Sentiment"," Summary","NER","Response Generator"], css=custom_css)
228
  tabs.launch(share=True)
229
 
 
73
 
74
  # Download the model file
75
  print('downloading llama model...')
76
+ # model_path_llama = hf_hub_download(repo_id=model_name_or_path, filename=model_basename, force_download=True, local_dir="./llama_model")
77
  print('finished download...')
78
  # Initialize the Llama model with appropriate settings for GPU
79
+ # lcpp_llm = Llama(
80
+ # model_path=model_path_llama,
81
+ # )
82
+
83
+ # def generate_email_response(email_prompt):
84
+ # # Check input received by the function
85
+ # print("Received prompt:", email_prompt)
86
+
87
+ # # Determine if the input is a shorthand command or an actual email
88
+ # if 'email to' in email_prompt.lower():
89
+ # # Assume it's a shorthand command, format appropriately
90
+ # formatted_prompt = f'''
91
+ # Email received: "{email_prompt}"
92
+ # Respond to this email, ensuring a professional tone, providing a concise update, and addressing any potential concerns the sender might have.
93
+ # Response:
94
+ # '''
95
+ # else:
96
+ # # Assume it's direct email content
97
+ # formatted_prompt = f'''
98
+ # Email received: "{email_prompt}"
99
+ # Respond to this email, ensuring a professional tone, providing a concise update, and addressing any potential concerns the sender might have.
100
+ # Response:
101
+ # '''
102
+
103
+ # # Generate response using Llama-2 model
104
+ # try:
105
+ # response = lcpp_llm(
106
+ # prompt=formatted_prompt,
107
+ # max_tokens=256,
108
+ # temperature=0.5,
109
+ # top_p=0.95,
110
+ # repeat_penalty=1.2,
111
+ # top_k=150,
112
+ # echo=True
113
+ # )
114
+ # generated_response = response["choices"][0]["text"]
115
+ # # Remove the input part from the output if it is included
116
+ # if formatted_prompt in generated_response:
117
+ # generated_response = generated_response.replace(formatted_prompt, '').strip()
118
+ # print("Generated response:", generated_response)
119
+ # return generated_response
120
+ # except Exception as e:
121
+ # print("Error in response generation:", str(e))
122
+ # return "Failed to generate response, please check the console for errors."
 
123
 
124
  def classify_sentiment(text):
125
  # Encode the text using the tokenizer
 
214
  title="NER Analysis",
215
  description="Performs Named Entity Recognition using spaCy and Transformer models."
216
  )
217
+ # iface_response = gr.Interface(
218
+ # fn=generate_email_response,
219
+ # inputs=gr.Textbox(lines=10, placeholder="Enter the email prompt..."),
220
+ # outputs=gr.Textbox(label="Generated Email Response"),
221
+ # title="Email Response Generator",
222
+ # description="Generate email responses using Llama-2 model."
223
+ # )
224
 
225
  # Using tabs to organize the interfaces
226
+ tabs = gr.TabbedInterface([iface_category, iface_sentiment,iface_summary,iface_ner], ["Category", "Sentiment"," Summary","NER"], css=custom_css)
227
  tabs.launch(share=True)
228