Ngadou commited on
Commit
20aaa1d
·
1 Parent(s): 3415ea5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import time
3
+ import openai
4
+ import json
5
+ import os
6
+ from transformers import pipeline
7
+ from transformers import AutoProcessor, AutoModelForCTC
8
+ openai.api_key = os.environ.get('OPENAI_KEY')
9
+
10
+
11
+
12
+
13
+ def is_scam(conversation):
14
+ # Create a list of messages
15
+ messages = [
16
+ {"role": "system", "content": "Is this chat a scam, a spam or is safe? Only answer in JSON format with 'classification': '' as string and 'reasons': '' as the most plausible reasons why. The reason should be explaning to the potential victim why the conversation is probably a scam"},
17
+ {"role": "user", "content": conversation},
18
+ ]
19
+
20
+ # Call the OpenAI API to generate a response
21
+ response = openai.ChatCompletion.create(
22
+ model="gpt-4", # Replace with the actual GPT-4 model ID
23
+ messages=messages
24
+ )
25
+
26
+ # Extract the generated text
27
+ text = response.choices[0].message['content']
28
+ text = json.loads(text)
29
+
30
+ # Get the decision and reasons from the JSON dictionary
31
+ decision = text["classification"]
32
+ reasons = text["reasons"]
33
+
34
+ # Return the response as it is, you will need to manually parse it into decisions and reasons
35
+ return decision, reasons
36
+
37
+ # Define the Gradio interface
38
+ gr.Interface(
39
+ fn=is_scam,
40
+ inputs='text',
41
+ outputs=[
42
+ gr.outputs.Textbox(label="Classification"),
43
+ gr.outputs.Textbox(label="Reason")
44
+ ],
45
+ live=True
46
+ ).launch()