EricGEGE commited on
Commit
f2a0349
·
verified ·
1 Parent(s): bd11bd5

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -121
app.py DELETED
@@ -1,121 +0,0 @@
1
- import time
2
-
3
- import numpy as np
4
- import pandas as pd
5
-
6
- from sentence_transformers import SentenceTransformer
7
-
8
- # from sklearn.decomposition import PCA
9
- from sklearn.metrics import DistanceMetric
10
-
11
- # import matplotlib.pyplot as plt
12
- # import matplotlib as mpl
13
- import warnings
14
- warnings.filterwarnings("ignore")
15
- import gradio as gr
16
- # from transformers.utils.hub import move_cache
17
- #
18
- # move_cache()
19
- # from mailersend import emails
20
-
21
- import asyncio
22
- from telegram import Bot
23
-
24
- token = '7370905765:AAHvmlw68cW7RxWzsJE1yxTzgf3xQFiokDo'
25
- chat_id = '7431171535'
26
- pd.set_option('display.max_colwidth', None)
27
- df_resume = pd.read_csv('QA.csv',encoding='latin-1')
28
- # df_resume['role'][df_resume['role'].iloc[-1] == df_resume['role']] = "Other" # relabel random role as "other"
29
- print(df_resume.head())
30
- model = SentenceTransformer("all-MiniLM-L6-v2")
31
- # file_name = 'questions.txt'
32
-
33
- import os
34
-
35
- import http.client, urllib
36
- def send_message(message):
37
- conn = http.client.HTTPSConnection("api.pushover.net:443")
38
- conn.request("POST", "/1/messages.json",
39
- urllib.parse.urlencode({
40
- "token": "ar2zh3pd82ujvjdmn27kdn5axapsjm",
41
- "user": "ucvqife229ek8qiymrircodezw2vm2",
42
- "message": message,
43
- }), { "Content-type": "application/x-www-form-urlencoded" })
44
- conn.getresponse()
45
-
46
-
47
- async def send_telegram_message(token, chat_id, message):
48
- bot = Bot(token=token)
49
- await bot.send_message(chat_id=chat_id, text=message)
50
- print("Message sent successfully.")
51
-
52
-
53
- def savevectorstore():
54
- # store embed vectors
55
- embedding_arr = model.encode(df_resume['question'])
56
- print(embedding_arr.shape)
57
- np.save('embeddings.npy', embedding_arr)
58
- # savevectorstore()
59
- # load embed vectors
60
- def rag_chain(question,name):
61
- embedding_arr = np.load('embeddings.npy')
62
- # print(embedding_arr.shape)
63
-
64
- # pca = PCA(n_components=2).fit(embedding_arr)
65
- # print(pca.explained_variance_ratio_)
66
-
67
- query = question
68
-
69
- query_embedding = model.encode(query)
70
-
71
- dist = DistanceMetric.get_metric('euclidean') # other distances: manhattan, chebyshev
72
-
73
- # compute pair wise distances between query embedding and all resume embeddings
74
- dist_arr = dist.pairwise(embedding_arr, query_embedding.reshape(1, -1)).flatten()
75
- # sort results
76
- idist_arr_sorted = np.argsort(dist_arr)
77
-
78
- # print(df_resume['name'].iloc[idist_arr_sorted[:1]].to_string(index=False))
79
- # print(df_resume['name'].iloc[idist_arr_sorted[:1]])
80
-
81
- que = f"**Most relevant question.**<br><br>{str(df_resume['question'].iloc[idist_arr_sorted[:1]].to_string(index=False)).replace('||','<br>')}"
82
- # que = df_resume['question'].iloc[idist_arr_sorted[:1]]
83
- ans = f"**Answer ideas.**<br><br>{str(df_resume['answer'].iloc[idist_arr_sorted[:1]].to_string(index=False)).replace('||','<br>')}"
84
- # ans = df_resume['answer'].iloc[idist_arr_sorted[:1]]
85
- # profit = df_resume['profit'].iloc[idist_arr_sorted[:1]].to_string(index=False)
86
- # product = df_resume['product'].iloc[idist_arr_sorted[:1]].to_string(index=False)
87
- # que1 = que
88
- # ans1 = ans
89
- # print(que1)
90
- # print(ans1)
91
- # que2= f'''Most relevant question
92
- #
93
- #
94
- # {que1}'''
95
- # ans2= f'''Answer ideas
96
- #
97
- #
98
- # {ans1}'''
99
- # print(que2)
100
- # print(ans2)
101
- # with open('questions.txt', 'a',encoding='utf-8') as file:
102
- # file.write(f"\n\n{question}\n\n{country}\n\n{whatsapp}\n\n{name}||{sales}||{profit}||{product}")
103
- message = f"{name}\n\n{question}\n\n{ans}"
104
- # asyncio.run(send_telegram_message(token, chat_id, message))
105
- send_message(message)
106
- return que,ans
107
- # rag_chain('I am very hungry.')
108
-
109
- desc = "This is an awesome ML App. I'm really excited to show you"
110
- long_desc = "如果我没有回答你的问题,把问题发给Eric吧。"
111
- search_interface = gr.Interface(
112
- fn=rag_chain,
113
- inputs=[gr.Textbox(label="Question"),gr.Textbox(label="Name")],
114
- outputs=[gr.Markdown(label="Most relevant question"),gr.Markdown(label="Answer ideas")],
115
- title="Ask Eric",
116
- description="Hi,我是数字分身,欢迎提问!",
117
- # theme=gr.themes.Glass
118
- article=long_desc
119
- )
120
-
121
- search_interface.launch(share=True,debug=True)