Spaces:
Sleeping
Sleeping
RichieBurundi
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
import sqlite3
|
4 |
|
5 |
-
model_name = "
|
6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
conn.close()
|
15 |
-
return files
|
16 |
|
17 |
-
def
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
prompt = f"{context}\nGenerate code based on the following input:\n{input_text}\n"
|
25 |
-
|
26 |
-
inputs = tokenizer(prompt, return_tensors="pt")
|
27 |
-
outputs = model.generate(**inputs, max_length=500)
|
28 |
-
generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
29 |
-
|
30 |
-
return generated_code
|
31 |
|
32 |
iface = gr.Interface(
|
33 |
-
fn=
|
34 |
inputs="text",
|
35 |
outputs="text",
|
36 |
-
title="
|
37 |
-
description="Enter your
|
38 |
)
|
39 |
|
40 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from bertopic import BERTopic
|
|
|
3 |
|
4 |
+
model_name = "RichieBurundi/Ariginalmodel"
|
|
|
|
|
5 |
|
6 |
+
try:
|
7 |
+
model = BERTopic.load(model_name)
|
8 |
+
except Exception as e:
|
9 |
+
print(f"Error loading model: {e}")
|
10 |
+
# Здесь можно добавить fallback логику или использовать другую модель
|
|
|
|
|
11 |
|
12 |
+
def generate_text(input_text):
|
13 |
+
try:
|
14 |
+
topics, probs = model.transform([input_text])
|
15 |
+
generated_text = model.generate_topic_labels(topics[0], probs[0], top_n=1)[0]
|
16 |
+
return generated_text
|
17 |
+
except Exception as e:
|
18 |
+
return f"Error generating text: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
iface = gr.Interface(
|
21 |
+
fn=generate_text,
|
22 |
inputs="text",
|
23 |
outputs="text",
|
24 |
+
title="Ariginal Model Text Generation",
|
25 |
+
description="Enter your text, and the model will generate a response."
|
26 |
)
|
27 |
|
28 |
iface.launch()
|