Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,10 +4,23 @@ from langchain_google_genai import GoogleGenerativeAIEmbeddings
|
|
4 |
import google.generativeai as genai
|
5 |
from langchain_community.vectorstores import FAISS
|
6 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
|
|
|
|
7 |
|
8 |
genai.configure(api_key="AIzaSyD2o8vjePJb6z8vT_PVe82lVWMD3_cBL0g")
|
9 |
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def predict(message :str ) -> str:
|
12 |
model = genai.GenerativeModel("gemini-pro")
|
13 |
his = []
|
@@ -20,7 +33,7 @@ def predict(message :str ) -> str:
|
|
20 |
history=his
|
21 |
)
|
22 |
response = chat.send_message(message)
|
23 |
-
return response.text
|
24 |
iface = gr.Interface(fn = predict,inputs = ["text"],outputs = "text")
|
25 |
iface.launch()
|
26 |
|
|
|
4 |
import google.generativeai as genai
|
5 |
from langchain_community.vectorstores import FAISS
|
6 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
7 |
+
import re
|
8 |
+
|
9 |
|
10 |
genai.configure(api_key="AIzaSyD2o8vjePJb6z8vT_PVe82lVWMD3_cBL0g")
|
11 |
|
12 |
|
13 |
+
def format_gemini_response(text):
|
14 |
+
|
15 |
+
bold_pattern = r"\*\*(.*?)\*\*"
|
16 |
+
italic_pattern = r"\*(.*?)\*"
|
17 |
+
code_pattern = r"```(.*?)```"
|
18 |
+
text = text.replace('\n', '<br>')
|
19 |
+
formatted_text = re.sub(code_pattern,"<pre><code>\\1</code></pre>",text)
|
20 |
+
formatted_text = re.sub(bold_pattern, "<b>\\1</b>", formatted_text)
|
21 |
+
formatted_text = re.sub(italic_pattern, "<i>\\1</i>", formatted_text)
|
22 |
+
|
23 |
+
return formatted_text
|
24 |
def predict(message :str ) -> str:
|
25 |
model = genai.GenerativeModel("gemini-pro")
|
26 |
his = []
|
|
|
33 |
history=his
|
34 |
)
|
35 |
response = chat.send_message(message)
|
36 |
+
return format_gemini_response(response.text)
|
37 |
iface = gr.Interface(fn = predict,inputs = ["text"],outputs = "text")
|
38 |
iface.launch()
|
39 |
|