Canstralian commited on
Commit
f6c4656
·
verified ·
1 Parent(s): 9eb2cff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -18
app.py CHANGED
@@ -1,22 +1,29 @@
1
- import requests
 
 
2
 
3
- # Replace with the correct Space API URL
4
- api_url = "https://hf.space/embed/Canstralian/WhiteRabbitNeo/api/predict/"
 
 
5
 
6
- # The input payload to send to the model
7
- payload = {"data": ["A new bug bounty to solve"]}
8
-
9
- try:
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
- # Parse the result
15
- result = response.json() # Parse the JSON response from the API
16
- print("Generated Result:", result["data"][0]) # Access the generated result
17
 
18
- # Optionally, save the result to a text file
19
- with open("generated_output.txt", "w") as f:
20
- f.write(result["data"][0])
21
- except requests.exceptions.RequestException as e:
22
- print("An error occurred:", e)
 
 
 
 
 
 
 
 
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()