File size: 2,552 Bytes
bc14905
 
 
 
 
149beb3
bc14905
 
 
 
 
 
149beb3
 
 
 
 
 
 
 
bc14905
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
065e984
bc14905
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149beb3
bc14905
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import streamlit as st
import google.generativeai as genai
import ast
import time
import os
import re

st.title('Verified Interseting fact geneartor')

secret_key = os.getenv("SECRET_KEY")
genai.configure(api_key=secret_key)

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


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

text=st.text_input('Write something to generate interseting facts. Like - Elephant , Bears')


prompt1='''Your work is to generate interseting facts.
important - generate fact and append it in a python list.
example-
text-india
your response-['india got independence in 1947','india first prime minister was nehru']
text - earth
your response-['earth look blue from space','earth is 3 planet in our solar system']
now generate upto 10 intersesting fact for the later text in correct specified format
text - '''

def check(x):
    try:
        y=ast.literal_eval(x)
        return y
    except:
        y=''
        st.warning('rerun code not splitted correctly')
        return y



submit=st.button('submit')

if text and submit:
    try:
        new = prompt1 + text
        model = genai.GenerativeModel('gemini-1.5-flash')
        response = model.generate_content(new)
        a = response.text
        b = extract_python_code(a)
        my_list = check(b)
        if isinstance(my_list, list):
            for i in my_list:
                c = get_gemini_response(i)
                new_list = check(c)
                if new_list[0] == 'True':
                    st.write(i)
                    st.write(c)
                time.sleep(2)
        else:
            st.warning('Error in checking.If error remains reload the page')
    except Exception as e:
        st.error(f"Error: {e}")
        st.write("Please try again!If error remains reload the page")