Spaces:
Runtime error
Runtime error
Commit
·
6b8f15b
1
Parent(s):
34ca82f
app - v1
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import gradio as gr
|
| 2 |
+
|
| 3 |
+
# def greet(name):
|
| 4 |
+
# return "Hello " + name + "!!"
|
| 5 |
+
|
| 6 |
+
# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
+
# iface.launch()
|
| 8 |
+
|
| 9 |
+
import gradio as gr
|
| 10 |
+
import torch
|
| 11 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 12 |
+
|
| 13 |
+
# Define the model and tokenizer
|
| 14 |
+
model_name = "atharvapawar/securix_Llama-2-7B-Chat-GGML"
|
| 15 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 16 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 17 |
+
|
| 18 |
+
def generate_response(user_input):
|
| 19 |
+
input_ids = tokenizer.encode(user_input, return_tensors="pt")
|
| 20 |
+
with torch.no_grad():
|
| 21 |
+
output = model.generate(input_ids)
|
| 22 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 23 |
+
return response
|
| 24 |
+
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=generate_response,
|
| 27 |
+
inputs=gr.inputs.Textbox(lines=2, label="Enter your question:"),
|
| 28 |
+
outputs=gr.outputs.Textbox(label="Generated Response:")
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
iface.launch()
|