shikharyashmaurya commited on
Commit
149beb3
1 Parent(s): bc14905

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -35
app.py CHANGED
@@ -3,14 +3,21 @@ 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.
@@ -43,44 +50,12 @@ text - '''
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')
@@ -91,7 +66,7 @@ if text and submit:
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:
 
3
  import ast
4
  import time
5
  import os
6
+ import re
 
7
 
8
  st.title('Verified Interseting fact geneartor')
9
 
10
  secret_key = os.getenv("SECRET_KEY")
11
  genai.configure(api_key=secret_key)
12
 
13
+ def extract_python_code(text):
14
+ pattern = r"```python\n(.*?)```"
15
+ match = re.search(pattern, text, re.DOTALL)
16
+ if match:
17
+ return match.group(1).strip()
18
+ else:
19
+ return None
20
+
21
 
22
  def get_gemini_response(input):
23
  prompt2='''you are an fact checker,you will get an text.
 
50
  def check(x):
51
  try:
52
  y=ast.literal_eval(x)
 
53
  return y
54
  except:
55
  y=''
56
  st.warning('rerun code not splitted correctly')
57
  return y
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
 
61
  submit=st.button('submit')
 
66
  model = genai.GenerativeModel('gemini-1.5-flash')
67
  response = model.generate_content(new)
68
  a = response.text
69
+ b = extract_python_code(a)
70
  my_list = check(b)
71
  if isinstance(my_list, list):
72
  for i in my_list: