Can Günen commited on
Commit
839d8bc
·
1 Parent(s): fa728c7

no token needed

Browse files
Files changed (2) hide show
  1. app.py +1 -2
  2. document_chatbot.py +5 -12
app.py CHANGED
@@ -13,10 +13,9 @@ with gr.Blocks() as demo:
13
  text_input = gr.Textbox(label="Enter text or URL to text file")
14
  with gr.Column():
15
  with gr.Row():
16
- api_key_input = gr.Textbox(label="Enter HF Token")
17
  picked_model = gr.Dropdown(["google/flan-t5-large", "google/flan-t5-base","google/flan-t5-small"], label="Models", interactive=True)
18
  load_configs = gr.Button("Load configs")
19
- load_configs.click(document_chatbot.load_token_and_model, inputs=[api_key_input, picked_model], outputs=[api_key_input])
20
 
21
  chatbot = gr.Chatbot()
22
 
 
13
  text_input = gr.Textbox(label="Enter text or URL to text file")
14
  with gr.Column():
15
  with gr.Row():
 
16
  picked_model = gr.Dropdown(["google/flan-t5-large", "google/flan-t5-base","google/flan-t5-small"], label="Models", interactive=True)
17
  load_configs = gr.Button("Load configs")
18
+ load_configs.click(document_chatbot.load_token_and_model, inputs=picked_model)
19
 
20
  chatbot = gr.Chatbot()
21
 
document_chatbot.py CHANGED
@@ -25,18 +25,11 @@ class DocumentChatbot:
25
  self.init_mes = ["According to the document, ", "Based on the text, ", "I think, ", "According to the text, ", "Based on the document you provided, "]
26
 
27
 
28
- def load_token_and_model(self, api_key, model_name):
29
- result = None
30
- if api_key[:2] == "hf":
31
- os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
32
- result = subprocess.run(["curl", "https://huggingface.co/api/whoami-v2", "-H", f"Authorization: Bearer {api_key}"], capture_output=True).stdout.decode()
33
- if result == '{"error":"Invalid username or password."}':
34
- return "Invalid API token"
35
- else:
36
- self.llm = HuggingFaceHub(repo_id=model_name, model_kwargs={"temperature":0, "max_length":512})
37
- self.chain = load_qa_chain(self.llm, chain_type="stuff")
38
- self.embeddings = HuggingFaceEmbeddings()
39
- return "Model and Token successfully loaded"
40
 
41
 
42
  def respond(self, text_input, question, chat_history):
 
25
  self.init_mes = ["According to the document, ", "Based on the text, ", "I think, ", "According to the text, ", "Based on the document you provided, "]
26
 
27
 
28
+ def load_token_and_model(self, model_name):
29
+ self.llm = HuggingFaceHub(repo_id=model_name, model_kwargs={"temperature":0, "max_length":512})
30
+ self.chain = load_qa_chain(self.llm, chain_type="stuff")
31
+ self.embeddings = HuggingFaceEmbeddings()
32
+ return "Model and Token successfully loaded"
 
 
 
 
 
 
 
33
 
34
 
35
  def respond(self, text_input, question, chat_history):