themeetjani commited on
Commit
7756bcc
1 Parent(s): 941da38

Upload entity_extraction.py

Browse files
Files changed (1) hide show
  1. pages/entity_extraction.py +58 -0
pages/entity_extraction.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from openai import OpenAI
2
+ client = OpenAI()
3
+ import streamlit as st
4
+ from streamlit import session_state
5
+ import json
6
+ import moviepy.editor as mp
7
+ from io import StringIO
8
+ import openai
9
+ import json
10
+ import os
11
+ import streamlit as st
12
+ import cv2 as cv
13
+ import tempfile
14
+ import os
15
+ os.environ['OPENAI_API_KEY'] = "sk-proj-ZbejHdD4ZgJ5FFJ6LjMNT3BlbkFJ1WHLrJMFL03D8cMWSoFY"
16
+ openai.api_key = os.environ['OPENAI_API_KEY']
17
+ def openai1(text1):
18
+ response = client.chat.completions.create(
19
+ model="gpt-4",
20
+ messages=[
21
+ {
22
+ "role": "system",
23
+ "content": "Identify the sentiment, whether sexual content not, abuse or not, related to academics or not (how frequent the conversation is related to non academic topics give it in percentage) and tone and phone number, name of teacher if mentioned, student feedback if mentioned and Whether the conversation is academic or non academic. Also add teacher behavior as positive and negative. \n<<REMEMBER>>\nGive output in json. generate a score 0 and 1. If Negative then 1 and if it's positive then it's 0. If the tone is aggresive then it should be 1. If phone number and email is given then it's 1. And academic should be as percentage. generate the total score and add academic percentage also. "
24
+ },
25
+ {
26
+ "role": "user",
27
+ "content": text1}
28
+ ],
29
+ temperature=1,
30
+ max_tokens=256,
31
+ top_p=1,
32
+ frequency_penalty=0,
33
+ presence_penalty=0
34
+ )
35
+ return response.choices[0].message.content
36
+
37
+ st.write("# Teacher session evaluation! 👋")
38
+ f = st.file_uploader("Upload file")
39
+ if f is not None:
40
+
41
+ # To convert to a string based IO:
42
+
43
+ tfile = tempfile.NamedTemporaryFile(delete=False)
44
+ tfile.write(f.read())
45
+ clip = mp.VideoFileClip(tfile.name)
46
+ # if clip.duration <=60:
47
+ clip.audio.write_audiofile("theaudio.mp3")
48
+ # else:
49
+ #clip.subclip(0,60).write_audiofile("theaudio.mp3")
50
+ # try:
51
+ audio_file= open("theaudio.mp3", "rb")
52
+ transcript_english = client.audio.translations.create(
53
+ model="whisper-1",
54
+ file=audio_file,temperature = 0).text
55
+ print(transcript_english)
56
+ st.text_area("Report", value = openai1(transcript_english))
57
+
58
+