Spaces:
Running
Running
Update model.py
Browse files
model.py
CHANGED
@@ -1,73 +1,72 @@
|
|
1 |
-
import google.generativeai as genai
|
2 |
-
import os
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
os.environ["GOOGLE_API_KEY"]
|
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 |
-
The
|
33 |
-
|
34 |
-
|
35 |
-
response
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
document
|
43 |
-
|
44 |
-
|
45 |
-
response
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
response
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
<
|
61 |
-
<
|
62 |
-
|
63 |
-
|
64 |
-
response
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
response
|
72 |
-
|
73 |
-
|
|
|
1 |
+
import google.generativeai as genai
|
2 |
+
import os
|
3 |
+
|
4 |
+
|
5 |
+
os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY")
|
6 |
+
genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
|
7 |
+
|
8 |
+
|
9 |
+
class AllModels:
|
10 |
+
def __init__(self):
|
11 |
+
self.model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
12 |
+
|
13 |
+
|
14 |
+
def road_map_model(self,subjects):
|
15 |
+
prompt = f"""Create an HTML format roadmap for learning {subjects} with proving week task . The roadmap should include the following sections:
|
16 |
+
|
17 |
+
Introduction: Brief overview of the subject and its importance.
|
18 |
+
|
19 |
+
Foundation: Fundamental concepts and theories to grasp before diving deeper.
|
20 |
+
|
21 |
+
Intermediate Level: More advanced topics building upon the foundation.
|
22 |
+
|
23 |
+
Advanced Level: Complex concepts, techniques, or applications within the subject.
|
24 |
+
|
25 |
+
Resources: List of recommended books, online courses, tutorials, and websites for further learning using hyperlink tag.
|
26 |
+
|
27 |
+
Projects: Hands-on projects or exercises to reinforce learning and apply knowledge.
|
28 |
+
|
29 |
+
Conclusion: Summary of key takeaways and encouragement for further exploration.
|
30 |
+
|
31 |
+
The HTML format should be visually appealing with appropriate headings, subheadings, bullet points, and hyperlinks where necessary. Ensure clarity and logical progression in the roadmap.
|
32 |
+
NOTE: The roadmap should be provided in pure HTML format without any Markdown or other formatting styles and In the html format dont need style tags and title tags"""
|
33 |
+
|
34 |
+
response = self.model.generate_content([prompt.format(subjects=subjects)])
|
35 |
+
return response.text
|
36 |
+
|
37 |
+
|
38 |
+
def summary_model(self,input_doc=None,image=None):
|
39 |
+
if input_doc:
|
40 |
+
prompt = """you are an intelligent assistant using the giving document summarize it shortly
|
41 |
+
document:
|
42 |
+
{document}
|
43 |
+
"""
|
44 |
+
response = self.model.generate_content([prompt.format(document=input_doc)])
|
45 |
+
return response.text
|
46 |
+
elif image:
|
47 |
+
prompt = """you are an intelligent assistant using the giving image summarize it and its content."""
|
48 |
+
response = self.model.generate_content([prompt,image])
|
49 |
+
return response.text
|
50 |
+
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
def book_creator(self,book_name):
|
55 |
+
prompt = """"Generate a detailed and extensive book titled '{book_title}'.
|
56 |
+
Please provide the content in HTML format with appropriate tags for headings, paragraphs,
|
57 |
+
NOTE: The book should be provided in pure "HTML" format without any "Markdown" or other formatting styles and In the html format dont need style tags and title tags
|
58 |
+
Ensure the HTML is well-structured and valid. Here is the beginning of the book in HTML:\n\n
|
59 |
+
<html>\n<head>\n<title>'{book_title}'</title>\n</head>\n<body>\n"
|
60 |
+
<h1>'{book_title}'</h1>\n"
|
61 |
+
<div>\n"""
|
62 |
+
|
63 |
+
response = self.model.generate_content([prompt.format(book_title=book_name)])
|
64 |
+
return response.text
|
65 |
+
|
66 |
+
def note_model(self,img):
|
67 |
+
prompt = """You are an intelligent Notes creator.create a notes using given screenshot
|
68 |
+
important note: if the screenshot not contain any text means you must say 'please upload a valid screenshot."""
|
69 |
+
|
70 |
+
response = self.model.generate_content([prompt,img])
|
71 |
+
return response.text
|
72 |
+
|
|