Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,50 @@
|
|
1 |
-
from dotenv import load_dotenv
|
2 |
-
from langchain import HuggingFaceHub, LLMChain
|
3 |
-
from langchain import PromptTemplates
|
4 |
-
import gradio
|
5 |
|
6 |
-
load_dotenv()
|
7 |
-
os.getenv('HF_API')
|
8 |
|
9 |
-
hub_llm = HuggingFaceHub(repo_id='facebook/blenderbot-400M-distill')
|
10 |
|
11 |
-
prompt = prompt_templates(
|
12 |
-
|
13 |
-
|
14 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
hub_chain = LLMChain(prompt=prompt, llm=hub_llm, verbose=True)
|
17 |
|
18 |
def responsenew(data):
|
19 |
-
return
|
20 |
|
21 |
|
22 |
gradio_interface = gradio.Interface(
|
|
|
1 |
+
# from dotenv import load_dotenv
|
2 |
+
# from langchain import HuggingFaceHub, LLMChain
|
3 |
+
# from langchain import PromptTemplates
|
4 |
+
# import gradio
|
5 |
|
6 |
+
# load_dotenv()
|
7 |
+
# os.getenv('HF_API')
|
8 |
|
9 |
+
# hub_llm = HuggingFaceHub(repo_id='facebook/blenderbot-400M-distill')
|
10 |
|
11 |
+
# prompt = prompt_templates(
|
12 |
+
# input_variable = ["question"],
|
13 |
+
# template = "Answer is: {question}"
|
14 |
+
# )
|
15 |
+
|
16 |
+
# hub_chain = LLMChain(prompt=prompt, llm=hub_llm, verbose=True)
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
# Sample code for AI language model interaction
|
23 |
+
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
24 |
+
import gradio
|
25 |
+
|
26 |
+
|
27 |
+
def simptok(data):
|
28 |
+
# Load pre-trained model and tokenizer (using the transformers library)
|
29 |
+
model_name = "gpt2"
|
30 |
+
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
31 |
+
model = GPT2LMHeadModel.from_pretrained(model_name)
|
32 |
+
|
33 |
+
# User input
|
34 |
+
user_input = data
|
35 |
+
|
36 |
+
# Tokenize input
|
37 |
+
input_ids = tokenizer.encode(user_input, return_tensors="pt")
|
38 |
+
|
39 |
+
# Generate response
|
40 |
+
output = model.generate(input_ids, max_length=50, num_return_sequences=1)
|
41 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
42 |
+
|
43 |
+
print(response)
|
44 |
|
|
|
45 |
|
46 |
def responsenew(data):
|
47 |
+
return simptok(data)
|
48 |
|
49 |
|
50 |
gradio_interface = gradio.Interface(
|