Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,29 @@
|
|
1 |
-
import
|
|
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
# Make a POST request to the API
|
11 |
-
response = requests.post(api_url, json=payload)
|
12 |
-
response.raise_for_status() # Raise an exception for HTTP errors
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
print("Generated Result:", result["data"][0]) # Access the generated result
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
|
5 |
+
# Load the model and tokenizer
|
6 |
+
model_path = "Canstralian/pentest_ai"
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_path)
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
9 |
|
10 |
+
# Function to handle user inputs and generate responses
|
11 |
+
def generate_text(instruction):
|
12 |
+
# Encode the input and ensure it fits within model limits
|
13 |
+
inputs = tokenizer.encode(instruction, return_tensors='pt', truncation=True, max_length=512)
|
|
|
|
|
|
|
14 |
|
15 |
+
# Generate the output with additional parameters for better control
|
16 |
+
outputs = model.generate(inputs, max_length=150, num_beams=5, temperature=0.7, top_p=0.95, do_sample=True)
|
|
|
17 |
|
18 |
+
# Decode and return the result
|
19 |
+
output_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
20 |
+
return output_text
|
21 |
+
|
22 |
+
# Create a Gradio interface
|
23 |
+
iface = gr.Interface(fn=generate_text,
|
24 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your question here..."),
|
25 |
+
outputs="text",
|
26 |
+
live=True)
|
27 |
+
|
28 |
+
# Launch the interface
|
29 |
+
iface.launch()
|