iamironman4279 commited on
Commit
6ddb33e
·
verified ·
1 Parent(s): 52de78a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import nltk
4
+ from nltk.stem import WordNetLemmatizer
5
+
6
+ # Load the intents from JSON file
7
+ with open('intents.json', 'r') as file:
8
+ intents_data = json.load(file)
9
+
10
+ lemmatizer = WordNetLemmatizer()
11
+
12
+ words = []
13
+ classes = []
14
+ documents = []
15
+ ignore_letters = ['?', '!', '.', ',']
16
+
17
+ for intent in intents_data['intents']:
18
+ for pattern in intent['patterns']:
19
+ word_list = nltk.word_tokenize(pattern)
20
+ words.extend(word_list)
21
+ documents.append((word_list, intent['tag']))
22
+ if intent['tag'] not in classes:
23
+ classes.append(intent['tag'])
24
+
25
+ words = [lemmatizer.lemmatize(word) for word in words if word not in ignore_letters]
26
+ words = sorted(set(words))
27
+
28
+ # Initialize Gradio components
29
+ output_text = gr.Textbox()
30
+ input_text = gr.Textbox()
31
+
32
+ # Define a Gradio function
33
+ def process_input(input_text):
34
+ # Your existing code here
35
+
36
+ # For example, let's return a sample output for demonstration
37
+ output_result = "Sample output for: " + input_text
38
+ return output_result
39
+
40
+ # Create the Gradio Interface
41
+ iface = gr.Interface(fn=process_input, inputs=input_text, outputs=output_text, live=True, capture_session=True)
42
+
43
+ # Launch the Gradio Interface
44
+ iface.launch()