cleopatro commited on
Commit
dc57eeb
β€’
1 Parent(s): fef9837

lets check

Browse files
Files changed (2) hide show
  1. requirements.txt +14 -0
  2. stream_lit.py +99 -0
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ anyio==3.6.2
2
+ click==8.1.3
3
+ colorama==0.4.6
4
+ fastapi==0.95.1
5
+ h11==0.14.0
6
+ idna==3.4
7
+ pydantic==1.10.7
8
+ python-dotenv==1.0.0
9
+ sniffio==1.3.0
10
+ starlette==0.26.1
11
+ textrazor==1.4.0
12
+ typing_extensions==4.5.0
13
+ uvicorn==0.22.0
14
+ replicate
stream_lit.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from collections import Counter
3
+ import textrazor
4
+ from dotenv import load_dotenv
5
+ import os
6
+ import pandas as pd
7
+ import replicate
8
+ import plotly.express as px
9
+
10
+ load_dotenv()
11
+ REPLICATE_API_TOKEN = os.getenv("REPLICATE_API_TOKEN")
12
+
13
+ text_ = """Alice: Hi there, is this Bob?
14
+ # Bob: Yes, speaking. Who's calling?
15
+ # Alice: Hey Bob, it's Alice from Acme Inc. We met at the conference last month.
16
+ # Bob: Oh, hey Alice! Good to hear from you. How can I help you today?
17
+ # Alice: Well, I was just calling because I wanted to touch base with you about that project we discussed at the conference. I was hoping we could set up a meeting to talk about it in more detail.
18
+ # Bob: Absolutely, I'd be happy to. When were you thinking?
19
+ # Alice: How about next Tuesday at 10 am?
20
+ # Bob: That works for me. Where should we meet?
21
+ # Alice: We can meet at our office in downtown. Here's the address: 123 Main St. Suite 400.
22
+ # Bob: Great. And just to confirm, your mobile number is still (555) 123-4567, right?
23
+ # Alice: Yes, that's correct.
24
+ # Bob: Perfect. I'll put the meeting in my calendar and send you a confirmation email with all the details.
25
+ # Alice: Sounds good, thanks Bob. Looking forward to it!"""
26
+
27
+ replicate.Client(api_token=REPLICATE_API_TOKEN)
28
+
29
+ def make_summary(text_):
30
+ output = replicate.run(
31
+ "replicate/flan-t5-xl:7a216605843d87f5426a10d2cc6940485a232336ed04d655ef86b91e020e9210",
32
+ input={"prompt": """Write the summary extract any useful information like name, number, and organization of the following conversation {text_to_summarize} """.format(text_to_summarize = text_)},
33
+ max_length = 500,
34
+ temperature = 0.7,
35
+ top_p = 0.95,
36
+ repetition_penalty = 1,
37
+ )
38
+ return " ".join(output)
39
+
40
+ load_dotenv()
41
+ textrazor.api_key = os.getenv("TEXT_RAZOR_API_KEY")
42
+
43
+ client = textrazor.TextRazor(extractors=["entities", "topics"])
44
+
45
+ def make_output(text:str):
46
+ response = client.analyze(text=text)
47
+ df = pd.DataFrame()
48
+ for entity in response.entities():
49
+ output_dict = {"id": "".join(list(entity.id or "None")),
50
+ "type": ", ".join(list(entity.dbpedia_types or "None")),
51
+ "wiki link": "".join(list(entity.wikipedia_link or "None"))}
52
+ df2 = pd.DataFrame.from_records([output_dict])
53
+ # df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True)
54
+ df = pd.concat([df, df2], ignore_index=True)
55
+ # print(entity.id)
56
+ df1 = df.drop_duplicates()
57
+
58
+ return(df)
59
+
60
+ st.title("CultureScout NLP Tool πŸ€–")
61
+
62
+ # taking user inputs for context search
63
+ st.write("***Enter Text You Need Help With:***")
64
+ user_input = st.text_input("Text Here:", "")
65
+
66
+ if st.button("πŸ”Ž Search It!"):
67
+ def predict_sentiment(data:str):
68
+ ans = make_output(user_input)
69
+ return ans
70
+ df = predict_sentiment(user_input)
71
+ df = df.drop_duplicates()
72
+ st.table(df)
73
+
74
+ id_df = predict_sentiment(user_input)['id']
75
+ id_freq = id_df.value_counts()
76
+ most_common_id = id_df.value_counts().index[0]
77
+
78
+ type_df = predict_sentiment(user_input)['type']
79
+ type_freq = type_df.value_counts()
80
+ most_common_type = type_df.value_counts().index[0]
81
+
82
+
83
+ st.bar_chart(id_freq)
84
+ st.bar_chart(type_freq)
85
+
86
+ st.write(f"Most appeared id is {most_common_id}.")
87
+ st.write(f"Most appeared type is {most_common_type}.")
88
+ st.write("""
89
+ """)
90
+
91
+ # taking user inputs for summarization
92
+ st.write("***Enter Text You Need to Summarize:***")
93
+ user_input1 = st.text_area("Text Here:", "")
94
+
95
+ if st.button("πŸͺ„ Summarize"):
96
+ def summarize(data:str):
97
+ ans1 = make_summary(user_input1)
98
+ return ans1
99
+ st.write(summarize(user_input1))