shikharyashmaurya
commited on
Commit
•
bc14905
1
Parent(s):
73e1849
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import google.generativeai as genai
|
3 |
+
import ast
|
4 |
+
import time
|
5 |
+
import os
|
6 |
+
# import re
|
7 |
+
# import json
|
8 |
+
|
9 |
+
st.title('Verified Interseting fact geneartor')
|
10 |
+
|
11 |
+
secret_key = os.getenv("SECRET_KEY")
|
12 |
+
genai.configure(api_key=secret_key)
|
13 |
+
|
14 |
+
|
15 |
+
def get_gemini_response(input):
|
16 |
+
prompt2='''you are an fact checker,you will get an text.
|
17 |
+
you will respond with two thing-
|
18 |
+
1.true false or unsure(if you are unsure or knowledge cutoff)
|
19 |
+
2.evidence in support or knowledge cutoff
|
20 |
+
you will respond in this format -
|
21 |
+
['true','false','unsure'],['evidence','knowledge cut off']
|
22 |
+
example-'dbhfv company founded in 2024'
|
23 |
+
response-['Unsure','knowledge cut off']
|
24 |
+
Now give response in the exact described format of the following text - '''
|
25 |
+
old=prompt2+input
|
26 |
+
model = genai.GenerativeModel('gemini-1.5-flash')
|
27 |
+
response1 = model.generate_content(old)
|
28 |
+
return response1.text
|
29 |
+
|
30 |
+
text=st.text_input('paste the text to fact check')
|
31 |
+
|
32 |
+
|
33 |
+
prompt1='''Your work is to generate interseting facts.
|
34 |
+
important - generate fact and append it in a python list.
|
35 |
+
example-
|
36 |
+
text-india
|
37 |
+
your response-['india got independence in 1947','india first prime minister was nehru']
|
38 |
+
text - earth
|
39 |
+
your response-['earth look blue from space','earth is 3 planet in our solar system']
|
40 |
+
now generate upto 10 intersesting fact for the later text in correct specified format
|
41 |
+
text - '''
|
42 |
+
|
43 |
+
def check(x):
|
44 |
+
try:
|
45 |
+
y=ast.literal_eval(x)
|
46 |
+
print(y)
|
47 |
+
return y
|
48 |
+
except:
|
49 |
+
y=''
|
50 |
+
st.warning('rerun code not splitted correctly')
|
51 |
+
return y
|
52 |
+
|
53 |
+
# if text:
|
54 |
+
# new=prompt1+text
|
55 |
+
# model=genai.GenerativeModel('gemini-1.5-flash')
|
56 |
+
# response=model.generate_content(new)
|
57 |
+
|
58 |
+
# a=response.text
|
59 |
+
# print(a)
|
60 |
+
# b=a[10:-5]
|
61 |
+
# print(b)
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
# # try:
|
66 |
+
# # my_list = ast.literal_eval(b)
|
67 |
+
# # print(my_list)
|
68 |
+
# # except:
|
69 |
+
# # my_list=''
|
70 |
+
# # st.warning('rerun code not splitted correctly')
|
71 |
+
|
72 |
+
# my_list=check(b)
|
73 |
+
|
74 |
+
# if isinstance(my_list,list):
|
75 |
+
# for i in my_list:
|
76 |
+
# c=get_gemini_response(i)
|
77 |
+
# new_list=check(c)
|
78 |
+
# if new_list[0]=='True':
|
79 |
+
# st.write(i)
|
80 |
+
# st.write(c)
|
81 |
+
# time.sleep(2)
|
82 |
+
# else:
|
83 |
+
# st.warning('rerun code error in checking')
|
84 |
+
|
85 |
+
|
86 |
+
submit=st.button('submit')
|
87 |
+
|
88 |
+
if text and submit:
|
89 |
+
try:
|
90 |
+
new = prompt1 + text
|
91 |
+
model = genai.GenerativeModel('gemini-1.5-flash')
|
92 |
+
response = model.generate_content(new)
|
93 |
+
a = response.text
|
94 |
+
b = a[10:-5]
|
95 |
+
my_list = check(b)
|
96 |
+
if isinstance(my_list, list):
|
97 |
+
for i in my_list:
|
98 |
+
c = get_gemini_response(i)
|
99 |
+
new_list = check(c)
|
100 |
+
if new_list[0] == 'True':
|
101 |
+
st.write(i)
|
102 |
+
st.write(c)
|
103 |
+
time.sleep(2)
|
104 |
+
else:
|
105 |
+
st.warning('Error in checking.If error remains reload the page')
|
106 |
+
except Exception as e:
|
107 |
+
st.error(f"Error: {e}")
|
108 |
+
st.write("Please try again!If error remains reload the page")
|
109 |
+
|
110 |
+
|
111 |
+
|