Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,27 @@
|
|
1 |
import streamlit as st
|
2 |
from langchain.prompts import PromptTemplate
|
3 |
-
# Recently the below import has been replaced by later one
|
4 |
-
# Use a pipeline as a high-level helper
|
5 |
-
# from transformers import pipeline
|
6 |
import transformers
|
7 |
-
|
8 |
-
# model_from_hugging_face = transformers.pipeline("text-generation", model="TheBloke/Llama-2-7B-Chat-GGML")
|
9 |
-
# Load model directly
|
10 |
# with ctransformers, you can load from Hugging Face Hub directly and specify a model file (.bin or .gguf files) using:
|
11 |
-
|
12 |
from ctransformers import AutoModelForCausalLM
|
13 |
-
|
14 |
-
# llm = AutoModelForCausalLM.from_pretrained("TheBloke/Llama-2-7B-Chat-GGML", model_file="llama-2-7b-chat.ggmlv3.q8_0.bin")
|
15 |
-
# # from langchain.llms import CTransformers
|
16 |
-
# from langchain_community.llms import CTransformers
|
17 |
-
|
18 |
#Function to get the response back
|
19 |
def getLLMResponse(form_input,email_sender,email_recipient,email_style):
|
20 |
-
|
21 |
-
|
22 |
# Wrapper for Llama-2-7B-Chat, Running Llama 2 on CPU
|
23 |
-
|
24 |
#Quantization is reducing model precision by converting weights from 16-bit floats to 8-bit integers,
|
25 |
#enabling efficient deployment on resource-limited devices, reducing model size, and maintaining performance.
|
26 |
-
|
27 |
#C Transformers offers support for various open-source models,
|
28 |
#among them popular ones like Llama, GPT4All-J, MPT, and Falcon.
|
29 |
-
|
30 |
-
|
31 |
-
#C Transformers is the Python library that provides bindings for transformer models implemented in C/C++ using the GGML library
|
32 |
-
|
33 |
llm = AutoModelForCausalLM.from_pretrained("TheBloke/Llama-2-7B-Chat-GGML", model_file="llama-2-7b-chat.ggmlv3.q8_0.bin")
|
34 |
-
|
35 |
-
|
36 |
#Template for building the PROMPT
|
37 |
template = """
|
38 |
Write a email with {style} style and includes topic :{email_topic}.\n\nSender: {sender}\nRecipient: {recipient}
|
39 |
\n\nEmail Text:
|
40 |
|
41 |
"""
|
42 |
-
|
43 |
#Creating the final PROMPT
|
44 |
prompt = PromptTemplate(
|
45 |
input_variables=["style","email_topic","sender","recipient"],
|
46 |
template=template,)
|
47 |
-
|
48 |
-
|
49 |
#Generating the response using LLM
|
50 |
#Last week langchain has recommended to use 'invoke' function for the below please :)
|
51 |
response=llm(prompt.format(email_topic=form_input,sender=email_sender,recipient=email_recipient,style=email_style))
|
|
|
1 |
import streamlit as st
|
2 |
from langchain.prompts import PromptTemplate
|
|
|
|
|
|
|
3 |
import transformers
|
|
|
|
|
|
|
4 |
# with ctransformers, you can load from Hugging Face Hub directly and specify a model file (.bin or .gguf files) using:
|
|
|
5 |
from ctransformers import AutoModelForCausalLM
|
|
|
|
|
|
|
|
|
|
|
6 |
#Function to get the response back
|
7 |
def getLLMResponse(form_input,email_sender,email_recipient,email_style):
|
8 |
+
|
|
|
9 |
# Wrapper for Llama-2-7B-Chat, Running Llama 2 on CPU
|
|
|
10 |
#Quantization is reducing model precision by converting weights from 16-bit floats to 8-bit integers,
|
11 |
#enabling efficient deployment on resource-limited devices, reducing model size, and maintaining performance.
|
|
|
12 |
#C Transformers offers support for various open-source models,
|
13 |
#among them popular ones like Llama, GPT4All-J, MPT, and Falcon.
|
|
|
|
|
|
|
|
|
14 |
llm = AutoModelForCausalLM.from_pretrained("TheBloke/Llama-2-7B-Chat-GGML", model_file="llama-2-7b-chat.ggmlv3.q8_0.bin")
|
|
|
|
|
15 |
#Template for building the PROMPT
|
16 |
template = """
|
17 |
Write a email with {style} style and includes topic :{email_topic}.\n\nSender: {sender}\nRecipient: {recipient}
|
18 |
\n\nEmail Text:
|
19 |
|
20 |
"""
|
|
|
21 |
#Creating the final PROMPT
|
22 |
prompt = PromptTemplate(
|
23 |
input_variables=["style","email_topic","sender","recipient"],
|
24 |
template=template,)
|
|
|
|
|
25 |
#Generating the response using LLM
|
26 |
#Last week langchain has recommended to use 'invoke' function for the below please :)
|
27 |
response=llm(prompt.format(email_topic=form_input,sender=email_sender,recipient=email_recipient,style=email_style))
|