Canstralian commited on
Commit
2bc3020
·
verified ·
1 Parent(s): 075f272

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +79 -61
  2. requirements.txt +6 -0
app.py CHANGED
@@ -1,61 +1,79 @@
1
- import streamlit as st
2
- import re
3
-
4
- def calculate(value, operation):
5
- """
6
- Perform the specified operation on the given value.
7
-
8
- Parameters:
9
- value (int or float): The number to operate on.
10
- operation (str): The operation to perform ('square', 'cube', 'double').
11
-
12
- Returns:
13
- int or float: The result of the operation.
14
- """
15
- operations = {
16
- 'square': lambda x: x ** 2,
17
- 'cube': lambda x: x ** 3,
18
- 'double': lambda x: x * 2
19
- }
20
- return operations[operation](value)
21
-
22
- def is_valid_input(user_input):
23
- """
24
- Validate user input using regular expressions to ensure it is a number.
25
-
26
- Parameters:
27
- user_input (str): The user input to validate.
28
-
29
- Returns:
30
- bool: True if the input is valid, False otherwise.
31
- """
32
- pattern = r'^\d+(\.\d+)?$' # Match integers and floating point numbers
33
- return bool(re.match(pattern, user_input))
34
-
35
- def main():
36
- """
37
- The main function to run the Streamlit app.
38
- """
39
- st.title("Enhanced Calculator")
40
-
41
- # Select operation
42
- operation = st.selectbox("Select an operation", ('square', 'cube', 'double'))
43
-
44
- # Slider for numeric input
45
- x = st.slider('Select a value', min_value=0.0, max_value=100.0, value=1.0, step=0.1)
46
-
47
- # Validate numeric input using regular expression
48
- user_input = st.text_input("Or enter a number:")
49
- if user_input and is_valid_input(user_input):
50
- x = float(user_input)
51
- elif user_input:
52
- st.error("Invalid input. Please enter a valid number.")
53
-
54
- # Calculate the result
55
- result = calculate(x, operation)
56
-
57
- # Display the result
58
- st.write(f'The {operation} of {x} is {result}')
59
-
60
- if __name__ == "__main__":
61
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer, AutoModel
3
+ import dask.dataframe as dd
4
+ from datasets import load_dataset
5
+ import torch
6
+
7
+ # Load models and tokenizer
8
+ def load_models():
9
+ # Load model 1
10
+ model_1 = AutoModel.from_pretrained("Canstralian/RedTeamAI")
11
+
12
+ # Load model 2
13
+ model_2 = AutoModel.from_pretrained("mradermacher/BashCopilot-6B-preview-GGUF")
14
+
15
+ # Load tokenizer and sequence classification model
16
+ tokenizer = AutoTokenizer.from_pretrained("bash1130/bert-base-finetuned-ynat")
17
+ model_3 = AutoModelForSequenceClassification.from_pretrained("bash1130/bert-base-finetuned-ynat")
18
+
19
+ return model_1, model_2, tokenizer, model_3
20
+
21
+ # Load dataset using Dask
22
+ def load_data():
23
+ # Example of loading a dataset using Dask (adjust paths as necessary)
24
+ splits = {'creative_content': 'data/creative_content-00000-of-00001.parquet'}
25
+ df = dd.read_parquet("hf://datasets/microsoft/orca-agentinstruct-1M-v1/" + splits["creative_content"])
26
+ return df.head()
27
+
28
+ # Function for model inference
29
+ def infer_model(input_text, model_type):
30
+ # Choose the model based on the input (you can add more models or conditions as needed)
31
+ if model_type == 'RedTeamAI':
32
+ model = models[0]
33
+ elif model_type == 'BashCopilot':
34
+ model = models[1]
35
+ elif model_type == 'BertModel':
36
+ model = models[3]
37
+ inputs = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True)
38
+ outputs = model(**inputs)
39
+ return outputs.logits.argmax(dim=-1).item()
40
+ else:
41
+ return "Model type not recognized."
42
+
43
+ # If you need to generate outputs based on the models directly, you can use:
44
+ # outputs = model.generate(input_text) or other inference methods depending on the model.
45
+ return f"Model {model_type} inference not implemented yet."
46
+
47
+ # Gradio Interface setup
48
+ def build_interface():
49
+ # Load models and data
50
+ model_1, model_2, tokenizer, model_3 = load_models()
51
+ global models
52
+ models = [model_1, model_2, tokenizer, model_3]
53
+
54
+ # Load the dataset (example function, you can add more functionality)
55
+ data_preview = load_data()
56
+
57
+ print(f"Dataset preview: {data_preview}")
58
+
59
+ # Create Gradio interface
60
+ with gr.Blocks() as demo:
61
+ gr.Markdown("# Chagrin AI - Model Inference & Dataset Explorer")
62
+
63
+ # Model selection dropdown
64
+ model_type = gr.Dropdown(choices=["RedTeamAI", "BashCopilot", "BertModel"], label="Choose Model")
65
+
66
+ # Textbox for user input
67
+ input_text = gr.Textbox(label="Enter your input text")
68
+
69
+ # Button to trigger inference
70
+ result = gr.Textbox(label="Inference Result")
71
+
72
+ submit_btn = gr.Button("Run Inference")
73
+ submit_btn.click(infer_model, inputs=[input_text, model_type], outputs=result)
74
+
75
+ demo.launch()
76
+
77
+ # Run the app
78
+ if __name__ == "__main__":
79
+ build_interface()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio==3.30.0 # For the Gradio app
2
+ transformers==4.38.0 # For Hugging Face transformers models
3
+ datasets==2.16.1 # For loading datasets from Hugging Face
4
+ dask==2023.8.1 # For parallel data processing with Dask
5
+ torch==2.1.0 # For model inference and handling PyTorch models
6
+ pandas==1.5.3 # For dataframe operations (especially for Dask)