import torch from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer import gradio as gr PROMPT = """ Given the following QUESTION, DOCUMENT and ANSWER you must analyze the provided answer and determine whether it is faithful to the contents of the DOCUMENT. The ANSWER must not offer new information beyond the context provided in the DOCUMENT. The ANSWER also must not contradict information provided in the DOCUMENT. Output your final verdict by strictly following this format: "PASS" if the answer is faithful to the DOCUMENT and "FAIL" if the answer is not faithful to the DOCUMENT. Show your reasoning. -- QUESTION (THIS DOES NOT COUNT AS BACKGROUND INFORMATION): What word used is used to classify a group or family of related living organisms; two examples being Clytostoma from tropical America and Syneilesis from East Asia? -- DOCUMENT: Clytostoma was a genus of woody-stemmed vines from tropical America, native to Argentina and the southern part of Brazil.Syneilesis is a genus of East Asian plants in the groundsel tribe within the Asteraceae. -- ANSWER: The two examples are plants. -- Your output should be in JSON FORMAT with the keys "REASONING" and "SCORE": {{"REASONING": , "SCORE": }} """ def greet(question, document, answer): tokenizer = AutoTokenizer.from_pretrained("PatronusAI/Llama-3-Patronus-Lynx-8B-Instruct") model = AutoModelForCausalLM.from_pretrained("PatronusAI/Llama-3-Patronus-Lynx-8B-Instruct", cache_dir='/tmp/cache', torch_dtype=torch.float16, low_cpu_mem_usage=True) inputs = tokenizer(PROMPT, return_tensors="pt") model.generate(inputs) generated_text = tokenizer.decode(inputs.input_ids[0]) print(generated_text) return generated_text demo = gr.Interface(fn=greet, inputs="text", outputs="text") demo.launch()