Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,14 @@
|
|
1 |
-
|
2 |
from transformers import AutoProcessor, AutoModelForImageTextToText
|
3 |
|
4 |
-
# Step 1: Load the model and processor from Hugging Face
|
5 |
processor = AutoProcessor.from_pretrained("enzer1992/AI-Guru")
|
6 |
model = AutoModelForImageTextToText.from_pretrained("enzer1992/AI-Guru")
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
# Process the input text
|
11 |
-
inputs = processor(input_text, return_tensors="pt")
|
12 |
-
|
13 |
-
# Generate the model's response
|
14 |
outputs = model.generate(**inputs)
|
15 |
-
|
16 |
-
# Decode and return the response
|
17 |
-
response = processor.decode(outputs[0], skip_special_tokens=True)
|
18 |
-
return response
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
while True:
|
23 |
-
user_input = input("You: ")
|
24 |
-
if user_input.lower() == "exit":
|
25 |
-
break
|
26 |
-
|
27 |
-
response = chat_with_model(user_input)
|
28 |
-
print(f"Model: {response}")
|
29 |
|
|
|
1 |
+
import gradio as gr
|
2 |
from transformers import AutoProcessor, AutoModelForImageTextToText
|
3 |
|
|
|
4 |
processor = AutoProcessor.from_pretrained("enzer1992/AI-Guru")
|
5 |
model = AutoModelForImageTextToText.from_pretrained("enzer1992/AI-Guru")
|
6 |
|
7 |
+
def generate_text(image):
|
8 |
+
inputs = processor(images=image, return_tensors="pt")
|
|
|
|
|
|
|
|
|
9 |
outputs = model.generate(**inputs)
|
10 |
+
return processor.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
11 |
|
12 |
+
iface = gr.Interface(fn=generate_text, inputs=gr.Image(), outputs="text")
|
13 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|