pratik-aivantage commited on
Commit
90a2343
·
verified ·
1 Parent(s): c5aa45b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -23,16 +23,17 @@
23
  # iface.launch(share=True)
24
 
25
  import gradio as gr
26
- from transformers import pipeline
27
 
28
- # Load the question answering pipeline
29
- qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad", tokenizer="distilbert-base-cased")
 
30
 
31
- # Define a function to generate answer for the given question
32
  def generate_answer(question):
33
- # Call the question answering pipeline
34
- result = qa_pipeline(question=question, context=None)
35
- return result["answer"]
 
36
 
37
  iface = gr.Interface(
38
  fn=generate_answer,
@@ -44,3 +45,21 @@ iface = gr.Interface(
44
 
45
  iface.launch(share=True) # Deploy the interface
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  # iface.launch(share=True)
24
 
25
  import gradio as gr
26
+ from transformers import AutoModelForCausalLM, AutoTokenizer
27
 
28
+ model_name = "abacusai/Smaug-72B-v0.1"
29
+ model = AutoModelForCausalLM.from_pretrained(model_name)
30
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
31
 
 
32
  def generate_answer(question):
33
+ inputs = tokenizer.encode("Question: " + question, return_tensors="pt")
34
+ outputs = model.generate(inputs, max_length=100, num_return_sequences=1, early_stopping=True, do_sample=True)
35
+ answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
36
+ return answer
37
 
38
  iface = gr.Interface(
39
  fn=generate_answer,
 
45
 
46
  iface.launch(share=True) # Deploy the interface
47
 
48
+
49
+ # from transformers import AutoModelForCausalLM, AutoTokenizer
50
+
51
+ # model_name = "abacusai/Smaug-72B-v0.1"
52
+ # model = AutoModelForCausalLM.from_pretrained(model_name)
53
+ # tokenizer = AutoTokenizer.from_pretrained(model_name)
54
+
55
+
56
+
57
+
58
+
59
+ # def generate_answer(question):
60
+ # inputs = tokenizer.encode("Question: " + question, return_tensors="pt")
61
+ # outputs = model.generate(inputs, max_length=100, num_return_sequences=1, early_stopping=True, do_sample=True)
62
+ # answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
63
+ # return answer
64
+
65
+