Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,142 +1,142 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
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 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
#
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
#
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
|
82 |
-
#
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
#
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
|
113 |
-
|
114 |
|
115 |
-
|
116 |
-
#
|
117 |
-
|
118 |
|
119 |
-
|
120 |
|
121 |
-
import openai
|
122 |
-
import gradio
|
123 |
|
124 |
-
openai.api_key = "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"
|
125 |
|
126 |
-
messages = [{"role": "system", "content": "Anhub Online Education Tutor for Any Subjects:"}]
|
127 |
|
128 |
-
def CustomChatGPT(user_input):
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
|
138 |
-
demo = gradio.Interface(fn=CustomChatGPT, inputs = "text", outputs = "text", title = "Anhub Metaverse Education Online Tutor for Any Subjects and any Languages @ 24 x 7:")
|
139 |
|
140 |
|
141 |
|
142 |
-
demo.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
import csv
|
6 |
+
import requests
|
7 |
+
import json
|
8 |
+
import pandas as pd
|
9 |
+
import concurrent.futures
|
10 |
+
from tqdm import tqdm
|
11 |
+
import shutil
|
12 |
+
import numpy as np
|
13 |
+
from matplotlib import pyplot as plt
|
14 |
+
import pickle
|
15 |
+
|
16 |
+
|
17 |
+
# Read list to memory
|
18 |
+
def read_list():
|
19 |
+
# for reading also binary mode is important
|
20 |
+
with open('mean_aoc_all_papers.pkl', 'rb') as fp:
|
21 |
+
n_list = pickle.load(fp)
|
22 |
+
return n_list
|
23 |
+
|
24 |
+
mean_citation_list = read_list()
|
25 |
+
|
26 |
+
def generate_plot_maoc(input_maoc):
|
27 |
+
sns.set(font_scale = 8)
|
28 |
+
sns.set(rc={'figure.figsize':(10,6)})
|
29 |
+
sns.set_style(style='whitegrid')
|
30 |
+
|
31 |
+
ax = sns.histplot(mean_citation_list, bins=100, kde=True, color='skyblue')
|
32 |
+
kdeline = ax.lines[0]
|
33 |
+
xs = kdeline.get_xdata()
|
34 |
+
ys = kdeline.get_ydata()
|
35 |
+
|
36 |
+
interpolated_y_maoc = np.interp(input_maoc, kdeline.get_xdata(), kdeline.get_ydata())
|
37 |
+
ax.scatter(input_maoc, interpolated_y_maoc,c='r', marker='*',linewidths=5, zorder=2)
|
38 |
+
ax.vlines(input_maoc, 0, interpolated_y_maoc, color='tomato', ls='--', lw=2)
|
39 |
+
epsilon = 0.3
|
40 |
+
ax.text(input_maoc + epsilon, interpolated_y_maoc + epsilon, 'Your paper', {'color': '#DC143C', 'fontsize': 13})
|
41 |
+
ax.set_xlabel("mean Age of Citation(mAoC)",fontsize=15)
|
42 |
+
ax.set_ylabel("Number of papers",fontsize=15)
|
43 |
+
ax.tick_params(axis='both', which='major', labelsize=12)
|
44 |
+
return plt
|
45 |
+
|
46 |
+
# sent a request
|
47 |
+
def request_to_respose(request_url):
|
48 |
+
request_response = requests.get(request_url, headers={'x-api-key': 'qZWKkOKyzP5g9fgjyMmBt1MN2NTC6aT61UklAiyw'})
|
49 |
+
return request_response
|
50 |
+
|
51 |
+
def return_clear():
|
52 |
+
return None, None, None, None, None
|
53 |
+
|
54 |
+
|
55 |
+
def compute_output(ssid_paper_id):
|
56 |
+
output_num_ref = 0
|
57 |
+
output_maoc = 0
|
58 |
+
oldest_paper_list = ""
|
59 |
+
|
60 |
+
request_url = f'https://api.semanticscholar.org/graph/v1/paper/{ssid_paper_id}?fields=references,title,venue,year'
|
61 |
+
r = request_to_respose(request_url)
|
62 |
+
if r.status_code == 200: # if successful request
|
63 |
+
s2_ref_paper_keys = [reference_paper_tuple['paperId'] for reference_paper_tuple in r.json()['references']]
|
64 |
+
filtered_s2_ref_paper_keys = [s2_ref_paper_key for s2_ref_paper_key in s2_ref_paper_keys if s2_ref_paper_key is not None]
|
65 |
+
total_references = len(s2_ref_paper_keys)
|
66 |
+
none_references = (len(s2_ref_paper_keys) - len(filtered_s2_ref_paper_keys))
|
67 |
+
s2_ref_paper_keys = filtered_s2_ref_paper_keys
|
68 |
+
|
69 |
+
# print(r.json())
|
70 |
+
|
71 |
+
s2_paper_key, title, venue, year = r.json()['paperId'], r.json()['title'], r.json()['venue'], r.json()['year']
|
72 |
+
reference_year_list = []
|
73 |
+
reference_title_list = []
|
74 |
+
for ref_paper_key in s2_ref_paper_keys:
|
75 |
+
request_url_ref = f'https://api.semanticscholar.org/graph/v1/paper/{ref_paper_key}?fields=references,title,venue,year'
|
76 |
+
r_ref = request_to_respose(request_url_ref)
|
77 |
+
if r_ref.status_code == 200:
|
78 |
+
s2_paper_key_ref, title_ref, venue_ref, year_ref = r_ref.json()['paperId'], r_ref.json()['title'], r_ref.json()['venue'], r_ref.json()['year']
|
79 |
+
reference_year_list.append(year_ref)
|
80 |
+
reference_title_list.append(title_ref)
|
81 |
|
82 |
+
# print(f'Number of references for which we got the year = {len(reference_year_list)}')
|
83 |
+
output_num_ref = len(reference_year_list)
|
84 |
+
aoc_list = [year - year_ref for year_ref in reference_year_list]
|
85 |
+
output_maoc = sum(aoc_list)/len(aoc_list)
|
86 |
+
|
87 |
+
sorted_ref_title_list = [x for _,x in sorted(zip(reference_year_list,reference_title_list))]
|
88 |
+
sorted_ref_year_list = [x for x,_ in sorted(zip(reference_year_list,reference_title_list))]
|
89 |
+
text = ""
|
90 |
+
sorted_ref_title_list = sorted_ref_title_list[:min(len(sorted_ref_title_list), 5)]
|
91 |
+
sorted_ref_year_list = sorted_ref_year_list[:min(len(sorted_ref_year_list), 5)]
|
92 |
+
for i in range(len(sorted_ref_year_list)):
|
93 |
+
text += '[' + str(sorted_ref_year_list[i]) + ']' + " Title: " + sorted_ref_title_list[i] + '\n'
|
94 |
|
95 |
+
oldest_paper_list = text
|
96 |
+
plot_maoc = generate_plot_maoc(output_maoc)
|
97 |
+
# print(plot_maoc)
|
98 |
|
99 |
+
return output_num_ref, output_maoc, oldest_paper_list, gr.update(value=plot_maoc)
|
100 |
+
|
101 |
+
|
102 |
+
with gr.Blocks() as demo:
|
103 |
+
ss_paper_id = gr.Textbox(label='Semantic Scholar ID',placeholder="Enter the Semantic Scholar ID here and press enter...", lines=1)
|
104 |
+
submit_btn = gr.Button("Generate")
|
105 |
+
with gr.Row():
|
106 |
+
num_ref = gr.Textbox(label="Number of references")
|
107 |
+
mAoc = gr.Textbox(label="Mean AoC")
|
108 |
+
with gr.Row():
|
109 |
+
oldest_paper_list = gr.Textbox(label="Top 5 oldest papers cited:",lines=5)
|
110 |
+
with gr.Row():
|
111 |
+
mAocPlot = gr.Plot(label="Plot")
|
112 |
|
113 |
+
clear_btn = gr.Button("Clear")
|
114 |
|
115 |
+
submit_btn.click(fn = compute_output, inputs = [ss_paper_id], outputs = [num_ref, mAoc, oldest_paper_list, mAocPlot])
|
116 |
+
# clear_btn.click(lambda: None, None, None, queue=False)
|
117 |
+
clear_btn.click(fn = return_clear, inputs=[], outputs=[ss_paper_id, num_ref, mAoc, oldest_paper_list, mAocPlot])
|
118 |
|
119 |
+
demo.launch()
|
120 |
|
121 |
+
# import openai
|
122 |
+
# import gradio
|
123 |
|
124 |
+
# openai.api_key = "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"
|
125 |
|
126 |
+
# messages = [{"role": "system", "content": "Anhub Online Education Tutor for Any Subjects:"}]
|
127 |
|
128 |
+
# def CustomChatGPT(user_input):
|
129 |
+
# messages.append({"role": "user", "content": user_input})
|
130 |
+
# response = openai.ChatCompletion.create(
|
131 |
+
# model = "gpt-3.5-turbo",
|
132 |
+
# messages = messages
|
133 |
+
# )
|
134 |
+
# ChatGPT_reply = response["choices"][0]["message"]["content"]
|
135 |
+
# messages.append({"role": "assistant", "content": ChatGPT_reply})
|
136 |
+
# return ChatGPT_reply
|
137 |
|
138 |
+
# demo = gradio.Interface(fn=CustomChatGPT, inputs = "text", outputs = "text", title = "Anhub Metaverse Education Online Tutor for Any Subjects and any Languages @ 24 x 7:")
|
139 |
|
140 |
|
141 |
|
142 |
+
# demo.launch()
|