Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,17 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import re
|
| 3 |
import torch
|
| 4 |
from transformers import pipeline
|
|
@@ -26,7 +39,9 @@ instruction = f"""
|
|
| 26 |
<|user|>
|
| 27 |
"""
|
| 28 |
|
| 29 |
-
def infer(
|
|
|
|
|
|
|
| 30 |
prompt = f"{instruction.strip()}\n{user_prompt}</s>"
|
| 31 |
print(f"PROMPT: {prompt}")
|
| 32 |
outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
|
@@ -41,7 +56,7 @@ def infer(user_prompt):
|
|
| 41 |
gr.Interface(
|
| 42 |
fn = infer,
|
| 43 |
inputs = [
|
| 44 |
-
gr.
|
| 45 |
],
|
| 46 |
outputs = [
|
| 47 |
gr.Textbox()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from gradio_client import Client
|
| 3 |
+
|
| 4 |
+
fusecap_client = Client("https://noamrot-fusecap-image-captioning.hf.space/")
|
| 5 |
+
|
| 6 |
+
def get_caption(image_in):
|
| 7 |
+
|
| 8 |
+
fusecap_result = fusecap_client.predict(
|
| 9 |
+
image_in, # str representing input in 'raw_image' Image component
|
| 10 |
+
api_name="/predict"
|
| 11 |
+
)
|
| 12 |
+
print(fusecap_result)
|
| 13 |
+
return fusecap_result
|
| 14 |
+
|
| 15 |
import re
|
| 16 |
import torch
|
| 17 |
from transformers import pipeline
|
|
|
|
| 39 |
<|user|>
|
| 40 |
"""
|
| 41 |
|
| 42 |
+
def infer(image_in):
|
| 43 |
+
|
| 44 |
+
user_prompt = get_caption(image_in)
|
| 45 |
prompt = f"{instruction.strip()}\n{user_prompt}</s>"
|
| 46 |
print(f"PROMPT: {prompt}")
|
| 47 |
outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
|
|
|
| 56 |
gr.Interface(
|
| 57 |
fn = infer,
|
| 58 |
inputs = [
|
| 59 |
+
gr.Image(type="filepath")
|
| 60 |
],
|
| 61 |
outputs = [
|
| 62 |
gr.Textbox()
|