Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,9 +6,10 @@ import requests
|
|
6 |
import torch
|
7 |
import streamlit as st
|
8 |
from langchain_huggingface import HuggingFaceEndpoint
|
|
|
9 |
from langchain_core.prompts import PromptTemplate
|
10 |
from langchain_core.output_parsers import StrOutputParser
|
11 |
-
from transformers import pipeline
|
12 |
from langdetect import detect
|
13 |
|
14 |
# ✅ Device setup
|
@@ -33,6 +34,12 @@ if "chat_history" not in st.session_state:
|
|
33 |
# ✅ Switched to Flan-T5 Model
|
34 |
MODEL_ID = "google/flan-t5-large"
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
def get_llm_hf_inference(model_id=MODEL_ID, max_new_tokens=500, temperature=0.3):
|
37 |
return HuggingFaceEndpoint(
|
38 |
repo_id=model_id,
|
|
|
6 |
import torch
|
7 |
import streamlit as st
|
8 |
from langchain_huggingface import HuggingFaceEndpoint
|
9 |
+
from langchain.llms import HuggingFacePipeline
|
10 |
from langchain_core.prompts import PromptTemplate
|
11 |
from langchain_core.output_parsers import StrOutputParser
|
12 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
13 |
from langdetect import detect
|
14 |
|
15 |
# ✅ Device setup
|
|
|
34 |
# ✅ Switched to Flan-T5 Model
|
35 |
MODEL_ID = "google/flan-t5-large"
|
36 |
|
37 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
38 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
|
39 |
+
pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1)
|
40 |
+
|
41 |
+
llm = HuggingFacePipeline(pipeline=pipe)
|
42 |
+
|
43 |
def get_llm_hf_inference(model_id=MODEL_ID, max_new_tokens=500, temperature=0.3):
|
44 |
return HuggingFaceEndpoint(
|
45 |
repo_id=model_id,
|