Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
{"role": "system", "content": "You are a helpful assistant."},
|
12 |
-
{"role": "user", "content": prompt},
|
13 |
-
],
|
14 |
-
)
|
15 |
-
return response.choices[0].message["content"]
|
16 |
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
inputs=gr.Textbox(lines=2, placeholder="Enter your message here..."),
|
20 |
outputs="text",
|
21 |
-
title="Akhil's
|
22 |
-
description="This is a chatbot using OpenAI's
|
23 |
-
|
24 |
-
|
25 |
-
if __name__ == "__main__":
|
26 |
-
interface.launch(share=True)
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
|
4 |
+
# Load pre-trained GPT-2 model and tokenizer
|
5 |
+
model_name = "google/gemma-7b"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
|
9 |
+
# Define function for generating response
|
10 |
+
def generate_response(prompt):
|
11 |
+
# Tokenize input prompt
|
12 |
+
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
# Generate response from model
|
15 |
+
output = model.generate(input_ids, max_length=50, num_return_sequences=1, temperature=0.9)
|
16 |
+
|
17 |
+
# Decode response tokens
|
18 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
19 |
+
|
20 |
+
return response
|
21 |
+
|
22 |
+
gr.Interface(
|
23 |
+
fn=generate_response,
|
24 |
inputs=gr.Textbox(lines=2, placeholder="Enter your message here..."),
|
25 |
outputs="text",
|
26 |
+
title="Akhil's Chatbot (powered by GPT2)",
|
27 |
+
description="This is a Basuc chatbot using OpenAI's GPT2. Ask it anything!",
|
28 |
+
theme="compact"
|
29 |
+
).launch()
|
|
|
|