import streamlit as st import google.generativeai as genai import ast import time import re def extract_python_code(text): pattern = r"```python\n(.*?)```" match = re.search(pattern, text, re.DOTALL) if match: return match.group(1).strip() else: return None import os secret_key = os.getenv("SECRET_KEY") genai.configure(api_key=secret_key) def get_gemini_response(input): prompt2='''you are an fact checker,you will get an text. you will respond with two thing- 1.true false or unsure(if you are unsure or knowledge cutoff) 2.evidence in support or knowledge cutoff you will respond in this format - ['true','false','unsure'],['evidence','knowledge cut off'] example-'dbhfv company founded in 2024' response-['Unsure','knowledge cut off'] Now give response in the exact described format of the following text - ''' old=prompt2+input model = genai.GenerativeModel('gemini-1.5-flash') response1 = model.generate_content(old) return response1.text st.title("Fact Checker") text=st.text_input('paste the text to fact check.Ask facts before that of 2021') prompt1='''impoprtant - give answer only in python list format. you will get an long paragraph of text. But the long text is diffcult to fact check in google. Your work is to break down the long text into small pieces so that it can be checked independently. You will break down text into a large number of list elements. example-'india got independence in 1947 its first prime minister was nehru'. response-['india got independence in 1947','india first prime minister was nehru'] impoprtant - give answer only in python list format Now you will give me a response of the given following text in the described format as a python list- ''' if text: new=prompt1+text model=genai.GenerativeModel('gemini-1.5-flash') response=model.generate_content(new) a=response.text b=extract_python_code(a) try: my_list = ast.literal_eval(b) except: my_list='' st.warning('rerun code') if isinstance(my_list,list): for i in my_list: c=get_gemini_response(i) st.write(i) st.write(c) time.sleep(2) else: st.warning('rerun code')