Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ try:
|
|
11 |
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
12 |
except Exception as e:
|
13 |
st.error(f"Error initializing the model '{model_name}': {e}")
|
|
|
14 |
|
15 |
# Function to generate OSINT results
|
16 |
def generate_osint_results(prompt: str, history: List[Dict[str, str]]) -> List[str]:
|
@@ -40,11 +41,14 @@ def generate_osint_results(prompt: str, history: List[Dict[str, str]]) -> List[s
|
|
40 |
messages.append({"role": "user", "content": prompt})
|
41 |
|
42 |
# Generate a response using the Hugging Face model
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
48 |
|
49 |
# Function for fine-tuning the model with the uploaded dataset
|
50 |
def fine_tune_model(dataset: str) -> str:
|
@@ -74,9 +78,8 @@ st.write("This tool generates OSINT-based results and allows you to fine-tune th
|
|
74 |
|
75 |
# User input for prompt and message history
|
76 |
prompt = st.text_area("Enter your OSINT prompt here...", placeholder="Type your prompt here...")
|
77 |
-
history = []
|
78 |
|
79 |
-
#
|
80 |
if "history" not in st.session_state:
|
81 |
st.session_state.history = []
|
82 |
|
@@ -92,6 +95,7 @@ dataset_file = st.file_uploader("Upload a dataset for fine-tuning", type=["txt"]
|
|
92 |
if dataset_file is not None:
|
93 |
# Save the uploaded file
|
94 |
dataset_path = os.path.join("uploads", dataset_file.name)
|
|
|
95 |
with open(dataset_path, "wb") as f:
|
96 |
f.write(dataset_file.read())
|
97 |
|
|
|
11 |
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
12 |
except Exception as e:
|
13 |
st.error(f"Error initializing the model '{model_name}': {e}")
|
14 |
+
generator = None # Set generator to None if model fails to load
|
15 |
|
16 |
# Function to generate OSINT results
|
17 |
def generate_osint_results(prompt: str, history: List[Dict[str, str]]) -> List[str]:
|
|
|
41 |
messages.append({"role": "user", "content": prompt})
|
42 |
|
43 |
# Generate a response using the Hugging Face model
|
44 |
+
if generator:
|
45 |
+
try:
|
46 |
+
response = generator(messages[-1]["content"], max_length=100, num_return_sequences=1)
|
47 |
+
return [response[0]["generated_text"]]
|
48 |
+
except Exception as e:
|
49 |
+
return [f"Error generating response: {e}"]
|
50 |
+
else:
|
51 |
+
return ["Error: Model initialization failed."]
|
52 |
|
53 |
# Function for fine-tuning the model with the uploaded dataset
|
54 |
def fine_tune_model(dataset: str) -> str:
|
|
|
78 |
|
79 |
# User input for prompt and message history
|
80 |
prompt = st.text_area("Enter your OSINT prompt here...", placeholder="Type your prompt here...")
|
|
|
81 |
|
82 |
+
# Initialize session state for message history
|
83 |
if "history" not in st.session_state:
|
84 |
st.session_state.history = []
|
85 |
|
|
|
95 |
if dataset_file is not None:
|
96 |
# Save the uploaded file
|
97 |
dataset_path = os.path.join("uploads", dataset_file.name)
|
98 |
+
os.makedirs("uploads", exist_ok=True)
|
99 |
with open(dataset_path, "wb") as f:
|
100 |
f.write(dataset_file.read())
|
101 |
|