File size: 3,752 Bytes
298d093
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import cohere
import streamlit as st
from serpapi import GoogleSearch
import requests
from geopy.geocoders import Nominatim
from PIL import Image
from io import BytesIO

st.title("Hi there!👨‍⚕️🩺")
st.title("Welcome to *Virtual Diagnosis*")
st.write("> **This app is meant to assist medical professionals ONLY**")

co = cohere.Client('QV5Gd5mELJPltvQm4kN8EH4ORFycFlun14ulhhSf')
prompt = st.text_input('What are the symptoms of your patient? (*Try to keep the symptoms meaningful*)')
geolocator = Nominatim(user_agent="geoapiExercises")

def get_coordinates(location):
    try:
        location = geolocator.geocode(location)
        return (location.latitude, location.longitude)
    except:
        return None

with open(r'C:\Users\vishwebh\Desktop\COHERE HACKATHON\symptoms_1.txt', 'r') as file:
    symptoms = [line.strip().lower() for line in file]
if prompt:
    if any(symptom in prompt.lower() for symptom in symptoms):
        response = co.generate(
            model = 'command-xlarge-nightly', #xlarge #medium #small
            prompt = f"user: Suggest prescription medications for these symptoms: {prompt}\nTLDR:", # 
            max_tokens=300,
            temperature=0.9,
            k=0,
            p=0.75,
            frequency_penalty=0,
            presence_penalty=0,
            stop_sequences=[],
            return_likelihoods='NONE'
        )

        text = format(response.generations[0].text)
        st.write('Prescription medications: %s' %text)
        st.download_button('Download example prescriptions', text)
        print("done!")

        
        params = {
        "engine": "google_shopping",
        "google_domain": "google.com",
        "q": text,
        "api_key": "5fab2158fd9fa6cb16925fd2ae13dc7d62d369d3b882074a8ab5a1a7225a034c" #"47e0ad25f66753bef13f195a4700f446bde4100454876d5ac6445c3822814b7b"
        }

        search = GoogleSearch(params)
        items = search.get_dict()


        for key, result in items.items():
            if "google_shopping_url" in result:
                st.caption(f'<a href="{result["google_shopping_url"]}">Click here for Google search page', unsafe_allow_html=True)
            else:
                pass

        for i in range(10):
            item = items['shopping_results'][i]
            response = requests.get(item['thumbnail'])
            st.image(Image.open(BytesIO(response.content)),
            caption=item['title'], width=400)
            st.text(item['source'])
            st.text(item['price'])
            st.caption(f'<a href="{item["link"]}">Click to buy</a>', unsafe_allow_html=True)


        address = st.text_input("Enter your location to search pharmacies near you: ( For best results, enter location in this *format: Area, City, Country*.)")

        if address:
            coordinates = get_coordinates(address)
            params = {
                "engine": "google_maps",
                "q": "Pharmacies",
                "ll": "@" + str(coordinates[0]) + "," + str(coordinates[1]) + ",15.1z",
                "type": "search",
                "api_key": "5fab2158fd9fa6cb16925fd2ae13dc7d62d369d3b882074a8ab5a1a7225a034c" #"47e0ad25f66753bef13f195a4700f446bde4100454876d5ac6445c3822814b7b"
                }

            search = GoogleSearch(params)
            results = search.get_dict()
            local_results = results["local_results"]
            for x in range(5):
                st.write("Name of pharmacy: ", local_results[x]["title"])
                st.write("address of pharmacy: ", local_results[x]["address"])
            
            print(type(local_results))

            st.image()
    
    else:
        st.write("Kindly pertain your inputs to possible medical symptoms only. Or try rephrasing.")