Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,63 +1,43 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
""
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
)
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
):
|
| 37 |
-
token = message.choices[0].delta.content
|
| 38 |
-
|
| 39 |
-
response += token
|
| 40 |
-
yield response
|
| 41 |
-
|
| 42 |
-
"""
|
| 43 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 44 |
-
"""
|
| 45 |
-
demo = gr.ChatInterface(
|
| 46 |
-
respond,
|
| 47 |
-
additional_inputs=[
|
| 48 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 49 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 50 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 51 |
-
gr.Slider(
|
| 52 |
-
minimum=0.1,
|
| 53 |
-
maximum=1.0,
|
| 54 |
-
value=0.95,
|
| 55 |
-
step=0.05,
|
| 56 |
-
label="Top-p (nucleus sampling)",
|
| 57 |
-
),
|
| 58 |
-
],
|
| 59 |
)
|
| 60 |
|
| 61 |
-
|
| 62 |
-
if
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from gradio_client import Client, handle_file
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Initialize the Gradio client
|
| 6 |
+
client = Client("sitammeur/PicQ")
|
| 7 |
+
|
| 8 |
+
# Gradio interface function
|
| 9 |
+
def gradio_predict(image):
|
| 10 |
+
# Save the image to a temporary path
|
| 11 |
+
temp_path = os.path.join("temp", "gradio_upload.png")
|
| 12 |
+
image.save(temp_path)
|
| 13 |
+
|
| 14 |
+
try:
|
| 15 |
+
# Use the Gradio client to predict the result
|
| 16 |
+
result = client.predict(
|
| 17 |
+
image=handle_file(temp_path),
|
| 18 |
+
question="extract the complete data from the image",
|
| 19 |
+
api_name="/predict"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Return the result as output
|
| 23 |
+
return f"Prediction: {result}"
|
| 24 |
+
|
| 25 |
+
finally:
|
| 26 |
+
# Clean up the temporary file
|
| 27 |
+
if os.path.exists(temp_path):
|
| 28 |
+
os.remove(temp_path)
|
| 29 |
+
|
| 30 |
+
# Gradio interface setup
|
| 31 |
+
iface = gr.Interface(
|
| 32 |
+
fn=gradio_predict,
|
| 33 |
+
inputs=gr.Image(type="pil"),
|
| 34 |
+
outputs="text",
|
| 35 |
+
live=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
+
if __name__ == '__main__':
|
| 39 |
+
if not os.path.exists("temp"):
|
| 40 |
+
os.makedirs("temp")
|
| 41 |
+
|
| 42 |
+
# Launch Gradio interface
|
| 43 |
+
iface.launch(share=True)
|